0

Is possible for grep, or egrep to see the exact word? See this example: those are my groups

groups
floppy audio video cdrom games plugdev power netdev scanner users

I want to see only power, but return the entire line

groups |grep --color -w power
floppy audio video cdrom games plugdev power netdev scanner users

Is easy to return only power using pipe with awk or cut

groups |grep --color -w power|cut -d ' ' -f 9
power

but my question is: is possible for grep or egrep command to return the exact word only?

1
  • 1
    FYI egrep is deprecated in favor of grep -E. Similarly fgrep is deprecated in favor of grep -F.
    – Ed Morton
    Jun 24, 2021 at 12:50

1 Answer 1

4

You can try with GNU grep as in grep -o power.

According to grep manual:

-o, --only-matching

Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.