Main Menu

Search

Showing posts with label Linker Article Linux GREP. Show all posts
Showing posts with label Linker Article Linux GREP. Show all posts

LINUX: How to Remove/Ignore/Not Display Blank Lines in A File Using grep command

Below grep command can be used for removing/ignoring and not displaying blank lines in a file.
grep -v -e '^$'  <filename>

Products to which Article Applies

All Linux Operating Systems

LINUX: GREP Command To Extract IP Addresses From Command Output Or File (How To Doc)

Below grep command can be used to extract IP addresses from a file.
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' <filename>

To extract IP addresses from command output below grep command can be used.

<command> | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

For example, below is grep command to extract IP addresses from "ip addr" command output.

ip addr | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

Below is sample output of above command.

10.10.10.137
10.20.11.12


Products to which Article Applies

All Linux Operating Systems


Additional Reference

https://www.shellhacks.com/regex-find-ip-addresses-file-grep/