Skip to main content
Post Closed as "Duplicate" by don_crissti, Gert, Archemar, dr_, Anthon
added 134 characters in body
Source Link
sysfiend
  • 143
  • 1
  • 6

I know I can use -A, -B and -C to show surrounding lines but all of them also show the matching line. What I'm trying to make here is so, in this example file:

foo
bar

I'd be doing something like grep <option> "bar" file and my output should be
foo

Side note: I know the way of doing it with another grep or using sed but I would like to do it just by using one time grep

I know I can use -A, -B and -C to show surrounding lines but all of them also show the matching line. What I'm trying to make here is so, in this example file:

foo
bar

I'd be doing something like grep <option> "bar" file and my output should be
foo

I know I can use -A, -B and -C to show surrounding lines but all of them also show the matching line. What I'm trying to make here is so, in this example file:

foo
bar

I'd be doing something like grep <option> "bar" file and my output should be
foo

Side note: I know the way of doing it with another grep or using sed but I would like to do it just by using one time grep

Source Link
sysfiend
  • 143
  • 1
  • 6

How to show previous line to matching pattern with grep and not the matching line?

I know I can use -A, -B and -C to show surrounding lines but all of them also show the matching line. What I'm trying to make here is so, in this example file:

foo
bar

I'd be doing something like grep <option> "bar" file and my output should be
foo