Linux/grep

From Omnia
Jump to: navigation, search

Print only matching:

grep -o '[PATTERN]'

Get IP addresses:

ifconfig | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
IP=`curl -s ip.oeey.com`
echo "$IP" | grep -o '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$'
echo $?  # 0 on success, 1 on fail

Ignore fully commented lines:

cat [file] | grep -v "^\s*#" | grep -v "^$"

keywords