I am running the following 2 sed commands. The first one adds newline characters where I want them, the second also adds newline characters where I want them, BUT also adds an extra one at the end of the file where there wasn't one before.
sed -e 's|\<LIST_G_STATEMENT>|&\
|g' ${XMLDIR}/statement_tmp_1.xml > ${XMLDIR}/statement_tmp_2.xml
sed -e 's|\</LIST_G_STATEMENT>|&\
|g' ${XMLDIR}/statement_tmp_2.xml > ${XMLDIR}/statement_tmp_3.xml
Using od -c on all 3 of the files gives the following output.
statement_tmp_1.xml (no \n at end of file)
1314700 T A T E M E N T > < / L I S T _
1314720 G _ S T A T E M E N T > < / G _
1314740 S E T U P > < / L I S T _ G _ S
1314760 E T U P > < / A R X S G P O >
1314777
statement_tmp_2.xml (no \n at end of file)
1314700 S T A T E M E N T > < / L I S T
1314720 _ G _ S T A T E M E N T > < / G
1314740 _ S E T U P > < / L I S T _ G _
1314760 S E T U P > < / A R X S G P O >
1315000
statement_tmp_3.xml (\n at end of file - where did it come from?)
1314700 S T A T E M E N T > < / L I S T
1314720 _ G _ S T A T E M E N T > \n < /
1314740 G _ S E T U P > < / L I S T _ G
1314760 _ S E T U P > < / A R X S G P O
1315000 > \n
1315002
I am running AIX 5.3
Basically, I either want it to stop adding the extra \n, or find a way of removing it.
s|...|&\n|just as well? – Joseph R. Nov 04 '13 at 10:59\nin the right hand side is not portable. – Stéphane Chazelas Nov 04 '13 at 11:03perlor other tool that can deal with binary data. – Stéphane Chazelas Nov 04 '13 at 11:06\<LF>is the traditional and POSIX way to add a LF character.\nwould typically substitute ancharacter in anything but GNUsed. – Stéphane Chazelas Nov 04 '13 at 11:07head -c -1can bite off the final newline. – wingedsubmariner Nov 04 '13 at 12:50-cnor negative numbers are POSIX. AIX head supports-cas an extension, but not negative numbers. – Stéphane Chazelas Nov 04 '13 at 13:43sedand other text utilities work on text files. A non-empty file that doesn't end in a newline is not a text file. Why are you trying to work with a non-text file? – Gilles 'SO- stop being evil' Nov 04 '13 at 21:52