连接多个文件,但包含文件名作为节标题 [英] Concatenate multiple files but include filename as section headers

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

问题描述

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

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?

我目前拥有的:

file1.txt = bluemoongoodbeer

file2.txt = awesomepossum

file3.txt = hownowbrowncow

cat file1.txt file2.txt file3.txt

想要的输出:

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

输出:

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

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

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

如果只有一个文件,则不会打印标题.如果使用 GNU utils,您可以使用 -v 来始终打印标题.

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天全站免登陆