M BUZZ CRAZE NEWS
// general

finding surrounding lines with grep

By Mia Morrison

I know how to use grep to output a line that matches a string. But what if I also want to output one line above every line containing a matching string, how do I do that?

1 Answer

do the following

grep -B 1 text_to_search_for file.txt
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy