0

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
Cyrus
  • 84,225
  • 14
  • 89
  • 153
user3489502
  • 3,451
  • 9
  • 38
  • 66

3 Answers3

2

find accepts multiple -execs in one command. For example:

find /disk/data/source/* -name '*.xml' -exec cat {} \; -exec echo "" \; > /home/userid/merged-file.xml 
oguz ismail
  • 1
  • 16
  • 47
  • 69
mik1904
  • 1,335
  • 9
  • 18
2

Using awk instead of cat:

find /disk/data/source/* -name '*.xml' \
    -exec awk 'NR!=FNR&&FNR==1{print ""} 1' {} + > /home/userid/merged-file.xml
oguz ismail
  • 1
  • 16
  • 47
  • 69
1

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.

0x5453
  • 12,753
  • 1
  • 32
  • 61