DEV Community

Liz Lam
Liz Lam

Posted on

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
Enter fullscreen mode Exit fullscreen mode

You would search for the word "happy" like this:

$ grep "happy" test.txt
happy
Enter fullscreen mode Exit fullscreen mode

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

$ grep -A 2 "happy" test.txt
happy
awake
coffee
Enter fullscreen mode Exit fullscreen mode

Top comments (0)