串联多个文件,但包含文件名作为节头 [英] Concatenate multiple files but include filename as section headers

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

问题描述

我想在终端中将多个文本文件连接成一个大文件。我知道我可以使用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天全站免登陆