LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help using cat command. (https://www.linuxquestions.org/questions/linux-newbie-8/help-using-cat-command-4175520502/)

stevenjeffries 09-29-2014 01:07 PM

Help using cat command.
 
Hello everyone.

I know there should be a simple way to do this, but I'm having a hard time finding this online.

Let's say that I have a directory with a bunch of text files, and I want to cat them all together.
Code:

cat *.txt > output.txt
does the job, but there aren't new line characters at the end of each of these text files, so the last line of each file is merged with the first line of the next file.

My question: how do I cat a group of files together, but throw a new line character between each file?

szboardstretcher 09-29-2014 01:15 PM

I would think the easiest way would be to add the newline to each file, then go about catting them normally.

Code:

sed -i -e '$a\' *.txt

stevenjeffries 09-29-2014 05:19 PM

That works for me, thanks szboardstretcher,


All times are GMT -5. The time now is 03:04 AM.