I want to cat all the files in a directory, but include some spacer between each one.
I think the simplest way is using the paste
command:
paste $(ls *) > file.out
Try
find . -type f -exec cat {} \; -exec echo "-- spacer --" \;
Obviously, the 'spacer' can be more than the simple example used here.
You might want to see pr(1)
, which may do what you want out-of-the-box.
To roll your own, expand this posix shell script fragment:
ls -1 | while read f; do cat "$f"; echo This is a spacer line; done > /tmp/outputfile
This might more readably be written as:
ls -1 | while read f; do
cat "$f"
echo This is a spacer line
done > /tmp/outputfile
You don't really need the -1
for ls
.
echo "" > blank.txt
cat f1.txt blank.txt f2.txt blank.txt f3.txt
To handle all of the files in a Directory (assuming ksh like Shell)
for file in * ; do
cat $file >> result.txt
echo "" >> result.txt
done
use awk
awk 'FNR==1{print ""}{print}' file* > out.txt