Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include a blank line between files I'm concatenating with "cat"?

Tags:

unix

I want to cat all the files in a directory, but include some spacer between each one.

like image 621
Matt Avatar asked Oct 31 '09 01:10

Matt


People also ask

Does cat add a new line?

The cat Command In this case, the cat command will read from the terminal and appends the data to the file. txt. This will add two lines to the end of file. txt.

How do I concatenate files with a cat?

Type the cat command followed by the file or files you want to add to the end of an existing file. Then, type two output redirection symbols ( >> ) followed by the name of the existing file you want to add to.

How do I append files together?

You can use cat with redirection to append a file to another file. You do this by using the append redirection symbol, ``>>''. To append one file to the end of another, type cat, the file you want to append, then >>, then the file you want to append to, and press <Enter>.


2 Answers

use awk

awk 'FNR==1{print ""}{print}' file* > out.txt
like image 135
ghostdog74 Avatar answered Sep 21 '22 15:09

ghostdog74


Try

find . -type f -exec cat {} \; -exec echo "-- spacer --" \;

Obviously, the 'spacer' can be more than the simple example used here.

like image 28
pavium Avatar answered Sep 22 '22 15:09

pavium