All Articles

The ABC's of grep - A

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!

A

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
school

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

$ grep "happy" test.txt
happy

To see the first 2 lines after happy, execute the following:

$ grep -A 2 "happy" test.txt
happy
awake
coffee

Want to see this in action? Check out the video below.

Published Oct 23, 2023

I love coffee, coding and writing.