I have a file that contains information like the following:
header info line 1
header info line 2
header info line 3
....
process: 1
info 1
info 2
info 3
process: 2
info 1
info 2
info 3
process: 3
info 1
info 2
info 3
What I want to do is grep for one of the process lines (e.x "process: 2") then delete the other process while keeping the header information. What I know is the number of lines after the "process: #" (Lets just use 3 for this example). What I don't know is how many process numbers there are. What I was trying was:
grep "process: 2" -A 3 file.txt
However I lose the header information. I want to keep the header info but get rid of all the other process info. I feel like I can do this with an egrep but I'm not sure how.
My desired output is the following:
header info line 1
header info line 2
header info line 3
....
process: 2
info 1
info 2
info 3