[Solved] Show lines above and below!

hello team -

anyone can help shwoing how to grep a file showing the lines above and below?

Thx
Bragabio

grep -B1 -A1 "searchme" input_file

--ahamed

in awk ..

$ awk '/pattern/{print x};{x=$0}'  ## before
$ awk '/pattern/{getline;print}' ## after
awk '/searchme/{print pre;print;getline;print}{pre=$0}' input_file

--ahamed

And if GNU grep is not available, you could try Bruce Barnett's context grep sed implementation.

using sed ..

$ sed -n '/pattern/{g;1!p;};h' ## before
$ sed -n '/pattern/{n;p;}' ## after

awsome!!! it worked fine!

Using sed...

sed -n '{H;/searchme/{n;H;x;s/.*\n\(.*\n.*\n\)/\1/;p}}' input_file

--ahamed