All Articles

The ABC's of p4 grep - B

Welcome to The ABC’s of p4 grep!

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

B

Much like the regular grep, use the -B flag to show the lines before the matching search term is found.

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 first line before happy, execute the following:

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

Published May 29, 2025

I love coffee, coding and writing.