Reputation: 9368
Suppose I have this file:
this is 1th line
this is 2th line
<<EOM
this is 3th line
EOM>>
this is 4th line
<<EOM
this is 5th line
EOM>>
this is 6th line
Is there anyway to run a command in bash to get:
this is 3th line
this is 5th line
and get the full text when there's no <<EOM
on it?
Upvotes: 0
Views: 98
Reputation: 2662
grep -q "<<EOM" file && awk '/<<EOM/{flag=1;next}/EOM>>/{flag=0}flag' file || cat file
if <<EOM
is found in file
it will print the lines between <<EOM
and EOM>>
with awk
. Else just cat
the file
Upvotes: 2
Reputation: 5950
This should work:
$ sed -n '/<<EOM/,/EOM>>/p' file | grep -v EOM || cat file
I mean...
And... this is better (avoid removing lines between markers containing EOM):
$ sed -n '/<<EOM/,/EOM>>/p' file | grep -vw '<<EOM\|EOM>>' || cat file
Upvotes: 4