I have a file uca.xml (Thunar configuration for custom actions):
<?xml encoding="UTF-8" version="1.0"?>
<actions>
<action>
<!--some code-->
</action>
</actions>
<--blank line here-->
Mind that the file ends with a blank line
I want a bash command/script to insert a file customAction.txt containing:
<action>
<!--custom configuration-->
</action>
so it will end looking like:
<?xml encoding="UTF-8" version="1.0"?>
<actions>
<action>
<!--some code-->
</action>
<action>
<!--custom configuration-->
</action>
</actions>
I tried a method given by jfgagne:
sed -n -i -e '/<\/actions>/r customAction.txt' -e 1x -e '2,${x;p}' -e '${x;p}' uca.xml
but it works only if there is at least one character (not a blank line) inserted below the tag.
My temporary workaround is a script:
echo "someDummyText" >> uca.xml
sed -n -i -e '/<\/actions>/r customaction.txt' -e 1x -e '2,${x;p}' -e '${x;p}' uca.xml
sed -i 's/someDummyText//' uca.xml
sed -i '${/^$/d;}' uca.xml
but I believe there is a more elegant, one-line solution with sed. Thanks in advance.
Note: this is my very post to the U&L and StackExchange community, so please be lenient with me and do not hesitate to correct me verbosely if I did something wrong. I read the SE FAQ and tried to search for an answer elsewhere with not much luck.
awk
/perl
/ed
. Why do you insist on usingsed
? – don_crissti Mar 31 '16 at 14:02