Tuesday, 10 September 2013

Extract a particular string from a file and output to another file using grep, awk, sed

Extract a particular string from a file and output to another file using
grep, awk, sed

I have a file and it contain the ff strings
2013-09-08 21:00:54 SMTP connection from [78.110.75.245]:5387 (TCP/IP
connection count = 20)
2013-09-08 21:00:54 SMTP connection from [188.175.142.13]:34332 (TCP/IP
connection count = 20)
2013-09-08 21:45:41 SMTP connection from [58.137.11.145]:51984 (TCP/IP
connection count = 20)
2013-09-08 21:49:26 SMTP connection from [109.93.248.151]:22273 (TCP/IP
connection count = 20)
2013-09-08 21:49:27 SMTP connection from [37.131.64.203]:7906 (TCP/IP
connection count = 20)
What I want to do is extract the IP address only and save it to a file.
I started with this
cat file-the-string.txt | sed '^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$' >
file-with-extracted-ips.txt
But I couldn't make it work.

No comments:

Post a Comment