General TC > Programming & Scripting - Unofficial

grepping for and sorting IP addresses

(1/1)

Rich:
Sometimes it's useful to be able to extract just the IP
addresses from a log file. To perform that function, I've
attached Grep.IPs. It can either be part of a pipe or it
can operate on a file directly:

--- Code: ---tc@E310:~$ Grep.IPs File.log
94.102.49.46
82.60.178.116
81.4.210.22
194.67.222.20
37.212.54.205
194.67.216.152
162.19.234.137
46.3.199.100
194.67.222.98
194.226.232.125
46.3.199.75
88.218.73.142
31.44.191.64
37.212.51.70
88.218.75.254
--- End code ---

If you want to sort the output just to group identical values
together, this would suffice:

--- Code: ---tc@E310:~$ Grep.IPs File.log | sort -n
31.44.191.64
37.212.51.70
37.212.54.205
46.3.199.100 <---------  .100  listed before  .75
46.3.199.75
81.4.210.22
82.60.178.116
88.218.73.142
88.218.75.254
94.102.49.46
162.19.234.137
194.226.232.125 <------  .226.  listed before  .67.
194.67.216.152
194.67.222.20
194.67.222.98
--- End code ---

But that won't sort all of the fields in ascending order:

Sort.IPs sorts on all 4 fields. It too can either be part of a pipe
or work on a file directly:

--- Code: ---tc@E310:~$ Grep.IPs File.log | Sort.IPs
31.44.191.64
37.212.51.70
37.212.54.205
46.3.199.75
46.3.199.100
81.4.210.22
82.60.178.116
88.218.73.142
88.218.75.254
94.102.49.46
162.19.234.137
194.67.216.152
194.67.222.20
194.67.222.98
194.226.232.125
--- End code ---

Navigation

[0] Message Index

Go to full version