Eightball,
You said you want to delete two lines before the matched line and one line after the matched line, but your example deletes two lines before the match line and the matched line (leaving the line after the match as it was).
The script Ygor provided will provide output matching your example output, but only works on Linux systems (according to the man pages provided on this site, the tac utility is not available on OpenSolaris, FreeBSD, OSX, or POSIX systems).
The following ed script should work on any of these systems:
#!/bin/ksh
# Usage: edscript pattern input_file output_file
# Find the 1st line in "input_file" selected by the basic regular
# expression "BRE"; delet the selected line, two lines before it, and
# one line after it; and write the update file to "output_file".
ed -s "$2" <<-END
/$1/-2;.+2d
w $3
END
save the above script in a file named edscript , make it executable by running the command:
chmod +x edscript
and then (assuming the input file you specified in your example is named in , execute the command:
edscript MICHAEL in out
to make the changes suggested by the sample output you provided and save the output in a file named out .