http://unstableme.blogspot.in/2008/05/print-currentnextprevious-line-using.html
Q. Print present line and previous line to the pattern that matches "Sriram" word below using awk:
Exercise 1:
cat sample.txt
Jadu previous line
Sriram present line
Varun next line
Gowda some line
Prasahanth some line
Output should be :
Jadu previous line
Sriram present line
Varun next line
Answer: You can do that using grep command, which supports -A and -B options
grep -B1 -A1 -i "sriram" sample.txt
Refer to "sed" solution given by jadu in the link above.