I need some help from the shell-script gurus out there.
I have a .txt file (log) that traces the IP addresses of clients on several lines, in a format similar to this one:
Line1 - Client IP [192.168.0.1] Other data Line2 - Client IP [192.168.0.2] Other data Line3 - Client IP [192.168.0.3] Other data Line4 - Client IP [192.168.0.2] Other data Line5 - Client IP [192.168.0.1] Other data ...
I need to create script that:
- extracts the IP addresses from this file
- groups the IP addresses (the same IP address is reported only once)
- outputs a file with the resulting IP addresses
For the previous example, the resulting file would be:
192.168.0.1 192.168.0.2 192.168.0.3
I am on the Windows OS, but I can use tools like Cygwin or Unix Tools (that provide Unix-like commands as grep, sort, etc. under Windows).
A solution without scripting could be good as well.
Thanks in advance for your help.
In PowerShell:
The Verbose Way –
Shorter version