Context : GNU/Linux Ubuntu.
I've a file made of thousands of lines and I'd like to have a script that will remove some lines between 2 specific keywords.
Initial file is like:
bla bla
...
bla bla
keyword1
bla bla
...
bla bla
keyword2
bla bla
...
bla bla
I would like to keep all file except the part between keyword1
and keyword2
.
Let's consider that keyword1
and keyword2
appear once and only once in the file; these keywords may be preceded or followed by other characters on their lines like spaces or <
or >
The lines with the keywords on them look like this (they are actually XML-based files):
<keyword2>
The keywords can be kept in the file or be removed along with the enclosed text, I'm fine with both outcomes.
I did not find out how to proceed using grep
. I'm not familiar with awk
; could it make it?
<keyword1>
as example, are you actually working with structured data (as in HTML or XML)? If so, using a dedicated parser likexmlstarlet
is preferable to using line-oriented text-processing tools likegrep
/sed
/awk
.sed
is not the correct tool for working with XML.