I'm want to remove all newline characters in a file between two XML tags using sed
on HP-UX in KornShell (ksh). I used sed
and got what I want except that when I turn the multi-line command to a single line (one-liner) it fails.
The file looks like this.
<NAME>
<FNAME>John</FNAME>
<LNAME>Doe</FNAME>
</NAME>
<NAME>
<FNAME>Jane</FNAME>
<LNAME>Doe</FNAME>
</NAME>
The following command in a script
sed '/<NAME/,/<\/NAME/{
{H;x;s/\n[ ^I]*//;x;};
/<NAME/{s/[ ^I]*//;h;};
/<\/NAME/{x;p;};
d;}' xmlfile
gives me exactly what I want
<NAME><FNAME>John</FNAME><LNAME>Doe</FNAME></NAME>
<NAME><FNAME>Jane</FNAME><LNAME>Doe</FNAME></NAME>
However, when I turn that into a one-liner like
sed '/<NAME/,/<\/NAME/{{H;x;s/\n[ ^I]*//;x;};/<NAME/{s/[ ^I]*//;h;};/<\/NAME/{x;p;};d;}' xmlfile
it fails and says
sed: There are too many '{'.
I don't know why and hope someone can tell me what the error message means and how to fix it. Don't preach readability; this is more out of curiosity.
The actual file I want to use this on is rather large around 15MB and there are approximately 250 lines between every <TAG>
and </TAG>
which I'm converting into one line. I pick sed
but am open to awk
or any other best-tool-for-the-job suggestions, but still would want to know why I'm getting the above error message.