I have a big file (more than 2000 lines). Where I have to insert a # at the beginning of 2 above lines and at the beginning of 1 below line after finding a pattern. Also insert # at the beginning of line where pattern found. Environment is Red Hat Linux. Also if you can explain, that would be great.
Take an example, please see below texts, Search "Fail" and # 2 lines before that and 1 line after that string (beginning of line). Also # line containing string "Fail".
Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult
Name
Number
Reason = Fail
Reasult
Name
Number
Reason = Pass
Reasult