Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

do the following

grep -B 1 text_to_search_for file.txt
share|improve this answer
That should be a -B right? – tony_sid Aug 8 '10 at 0:06
Sorry, yes. -B for Before. -C is for before and after. Corrected answer, I had misread the question – bryan Aug 8 '10 at 0:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .