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

我目前拥有的:

file1.txt = bluemoongoodbeer

file2.txt = awesomepossum

file3.txt = hownowbrowncow

cat file1.txt file2.txt file3.txt

期望的输出:

file1

bluemoongoodbeer

file2

awesomepossum

file3

hownowbrowncow

当前回答

这是我通常如何处理这样的格式:

for i in *; do echo "$i"; echo ; cat "$i"; echo ; done ;

我通常将cat管道到grep中以获取特定的信息。

其他回答

你可以使用这个简单的命令来代替for循环,

ls -ltr | awk '{print $9}' | xargs head

这里有一个非常简单的方法。您说您想cat,这意味着您想查看整个文件。但是你还需要打印文件名。

试试这个

Head -n99999999 *或Head -n99999999 file1.txt file2.txt file3.txt

希望这能有所帮助

如果你喜欢颜色,试试这个:

for i in *; do echo; echo $'\e[33;1m'$i$'\e[0m'; cat $i; done | less -R

or:

tail -n +1 * | grep -e $ -e '==.*'

或者:(安装包'multitail')

multitail *

如果你想要的结果与你想要的输出格式相同,你可以尝试:

for file in `ls file{1..3}.txt`; \
do echo $file | cut -d '.' -f 1; \ 
cat $file  ; done;

结果:

file1
bluemoongoodbeer
file2
awesomepossum
file3
hownowbrowncow

你可以在剪切之前和之后加上echo -e,这样你就有了行与行之间的间距:

$ for file in `ls file{1..3}.txt`; do echo $file | cut -d '.' -f 1; echo -e; cat $file; echo -e  ; done;

结果:

file1

bluemoongoodbeer

file2

awesomepossum

file3

hownowbrowncow
find . -type f -exec cat {} \; -print