All Articles

The ABC's of grep - O

O

Use the -o flag to ​only see the part of pattern you are interested in.

Let’s return to our handy dandy test.txt file with the following content:

sad
happy
awake
coffee
work
school

If we grep for “wake” we will see the entire line:

$ grep "wake" test.txt
awake

Using the -o flag, the output is exactly what we are searching for:

$ grep -o "wake" test.txt
wake

Published Nov 12, 2023

I love coffee, coding and writing.