Welcome to The ABC’s of grep!
Here we will explore the different flags for our beloved command and give it the accolades it deserves.
Let’s start!
Use the -A flag to show the lines after the matching search term is found.
Suppose you have a file named test.txt with the following content:
sad
happy
awake
coffee
work
schoolYou would search for the word “happy” like this:
$ grep "happy" test.txt
happyTo see the first 2 lines after happy, execute the following:
$ grep -A 2 "happy" test.txt
happy
awake
coffeeWant to see this in action? Check out the video below.