How should I modify this line to add a new line (\n) between each file being concatenated?
find /disk/data/source/* -name '*.xml' -exec cat {} \; > /home/userid/merged-file.xml
How should I modify this line to add a new line (\n) between each file being concatenated?
find /disk/data/source/* -name '*.xml' -exec cat {} \; > /home/userid/merged-file.xml
find accepts multiple -exec
s in one command. For example:
find /disk/data/source/* -name '*.xml' -exec cat {} \; -exec echo "" \; > /home/userid/merged-file.xml
Using awk instead of cat:
find /disk/data/source/* -name '*.xml' \
-exec awk 'NR!=FNR&&FNR==1{print ""} 1' {} + > /home/userid/merged-file.xml
Since you are already using find
, try this:
find /disk/data/source/* -name '*.xml' -exec cat {} \; -exec echo \; > /home/userid/merged-file.xml
And if you want to get rid of the extra newline at the end, you can add | head -n-1
.