Extract IP address

One liner with grep to extract the IP addresses from a file.

grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' /path/to/file

The "-o" option prints only the matched parts.

One liner with perl:

perl -ne 'print if s/.*((\d{1,3}\.){3}\d{1,3}).*/\1/' /path/to/file

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Extract "to", "from" and "ctladdr" emails from maillog

Grep using "-P", Perl regexp so the non-greedy ".*?" expression works:

grep -Po '(to|from|ctladdr)=<.*?>' /var/log/maillog

Comment