From f44e7f04d1ae56a6a80e73d7beb2f8ad0fb2beed Mon Sep 17 00:00:00 2001 From: "Ap.Muthu" Date: Wed, 4 Sep 2024 19:36:44 +0530 Subject: [PATCH] Bash sort IPs uniquely https://www.oreilly.com/library/view/bash-cookbook/0596526784/ch08s03.html --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 762d917..022e269 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,12 @@ curl -s ifconfig.me/ip # Using curl silently without progress bar wget -qO- ifconfig.me/ip # Using wget quietly ```` +### Sort IPs +```bash +# Remove Comments and append new IPs and then: +grep -v "#" ip_blocked.txt | uniq | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n > ip_blocked_sorted.txt +``` + ### Parse Apache2 access.log ```bash cat /var/log/apache2/access.log | awk '{print $1}' | sort -nr | uniq -c | sort -nr | head -n 25