![]() |
grep and store two lines in other file
Dear all,
I have following contents #1 aaaa #2 bbb #3 ccc I want to grep "#2" and want the output as #1 aaaa #3 ccc Please help me using shell script With regards, Keerti |
Code:
grep -vA1 "#2" foo.txt |
This will do it:
Code:
grep -v "`grep -A1 '#2' filename`" filename |
If you want to store the output in a new file just add a redirection. For example using AlucardZero's code:
Code:
grep -vA1 "#2" foo.txt > newfileFordeck |
Or if it doesn't have to be grep:
Code:
awk '/2/{getline;next}1' file |
Sed is another possibility to accomplish that:
Code:
sed -i '/^#2/ {N;d}' file |
Code:
$ ruby -ne 'gets && next if /^#2/;print ' file |
| All times are GMT -5. The time now is 10:22 PM. |