Show only part of the line found by grep (but not the part that matches the pattern)

greptext processing

In ifcfg-eth0, I managed to grep "DEVICE=eth0" by using

grep "DEVICE=" ifcfg-eth0

But how can I grep pattern to show only "eth0"?

Best Answer

grep is not really the tool for this (although versions of GNU grep offer various options that do similar things). sed or awk are far better suited for this task.

awk -F= '$1 == "DEVICE" { print $2 }'
sed -n 's/^DEVICE=//p'
Related Question