0

When I run cat 1.txt 2.txt > result.txt, I want result.txt to have a linebreak between the end of the contents of 1.txt and the beginning of the contents of 2.txt. How do I do this?

Kenster
  • 23,465
  • 21
  • 80
  • 106
Username
  • 3,463
  • 11
  • 68
  • 111
  • possible duplicate of [Concatenating Files And Insert New Line In Between Files](http://stackoverflow.com/questions/8183191/concatenating-files-and-insert-new-line-in-between-files) – gsp8181 May 12 '15 at 14:08
  • possible duplicate of [How do I include a blank line between files I'm concatenating with "cat"?](http://stackoverflow.com/questions/1653063/how-do-i-include-a-blank-line-between-files-im-concatenating-with-cat) – fedorqui May 12 '15 at 14:11

1 Answers1

2

One of many options is:

echo | cat 1.txt - 2.txt > result.txt

The - argument says 'accept standard input' and the echo provides the new line

This option only works cleanly for 2 files. If you are actually looking at many files etc then for example:

(cat 1.txt; echo; cat 2.txt; echo; cat 3.txt) > result.txt

Would work; It's worth noting this spawns more cat processes.

tolanj
  • 3,651
  • 16
  • 30