All Articles

The ABC's of p4 grep - C

Welcome to The ABC’s of p4 grep!

Here we will explore the different flags for the p4 grep commands.

C

Much like regular grep, use the -C flag to show the context around the matching search term.

Suppose you have a file named test.txt with the following content:

sad
happy
awake
coffee
work
school

You would search for the word “happy” like this:

$ grep -e happy test.txt
//depot/test.txt#6:happy

To see the lines before and after “happy”, execute the following:

$ grep -C 1 -e happy test.txt
//depot/test.txt#6-sad
//depot/test.txt#6:happy
//depot/test.txt#6-awake

Published May 29, 2025

I love coffee, coding and writing.