Use the -B flag to show the lines before the matching search term is found.
Remember our file test.txt with the following content:
sad
happy
awake
coffee
work
schoolAs before, we would search for the word “happy” like this:
$ grep "happy" test.txt
happyTo see the first line before happy, execute the following:
$ grep -B 1 "happy" test.txt
sad
happyWant to see this in action? Check out the video below.