猫多个文件,但包括文件名作为标题 [英] cat multiple files but include filename as headers

查看:127
本文介绍了猫多个文件,但包括文件名作为标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将多个文本文件连接成终端中的一个大文件。我知道我可以使用cat命令来做到这一点。但是,我希望每个文件的文件名位于该文件的数据转储之前。任何人都知道如何做到这一点?



我现在有什么:

  file1.txt = bluemoongoodbeer 

file2.txt = awesomepossum

file3.txt = hownowbrowncow

cat file1.txt file2.txt file3.txt

所需输出:

  file1 

bluemoongoodbeer

file2

awesomepossum

file3

hownowbrowncow


解决方案

正在寻找相同的东西,这提示:

  tail -n +1 file1.txt file2.txt file3.txt 


$ b

输出:

  ==> ; file1.txt< == 
< file1.txt的内容>

==> file2.txt< ==
< file2.txt的内容>

==> file3.txt< ==
< file3.txt的内容>

如果只有一个文件,那么标题将不会被打印。如果使用GNU utils,您可以使用 -v 来始终打印标题。


I would like to concatenate a number of text files into one large file in terminal. I know I can do this using the cat command. However, I would like the filename of each file to precede the "data dump" for that file. Anyone know how to do this?

what I currently have:

file1.txt = bluemoongoodbeer

file2.txt = awesomepossum

file3.txt = hownowbrowncow

cat file1.txt file2.txt file3.txt

desired output:

file1

bluemoongoodbeer

file2

awesomepossum

file3

hownowbrowncow

解决方案

Was looking for the same thing, and found this to suggest:

tail -n +1 file1.txt file2.txt file3.txt

Output:

==> file1.txt <==
<contents of file1.txt>

==> file2.txt <==
<contents of file2.txt>

==> file3.txt <==
<contents of file3.txt>

If there is only a single file then the header will not be printed. If using GNU utils, you can use -v to always print a header.

这篇关于猫多个文件,但包括文件名作为标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆