开发者

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

I want to cat all the files in a dir开发者_StackOverflow中文版ectory, but include some spacer between each one.


use awk

awk 'FNR==1{print ""}{print}' file* > out.txt


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.


I think the simplest way is using the paste command:

paste $(ls *) > file.out


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜