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

我目前拥有的:

file1.txt = bluemoongoodbeer

file2.txt = awesomepossum

file3.txt = hownowbrowncow

cat file1.txt file2.txt file3.txt

期望的输出:

file1

bluemoongoodbeer

file2

awesomepossum

file3

hownowbrowncow

当前回答

我做了一个组合:

Cat /sharedpath/{unique1,unique2,unique3}/filename >新文件

and

Tail -n +1 file1 file2

到这个:

Tail -n +1 /sharedpath/{folder1,folder2,…,folder_n}/文件。扩展名| cat > /sharedpath/newfile

结果是一个newfile,其中包含{}括号中每个子文件夹(unique1,unique2..)的内容,以子文件夹名称分隔。

注意unique1 = folder1

在我的例子中是文件。扩展名在所有子文件夹中具有相同的名称。

其他回答

为了解决这个问题,我通常使用以下命令:

$ cat file{1..3}.txt >> result.txt

如果文件数量很大,这是一种非常方便的连接文件的方法。

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

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

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

这也可以做到:

$ find . -type f -print -exec cat {} \;
./file1.txt
Content of file1.txt
./file2.txt
Content of file2.txt

下面是对命令行参数的解释:

find    = linux `find` command finds filenames, see `man find` for more info
.       = in current directory
-type f = only files, not directories
-print  = show found file
-exec   = additionally execute another linux command
cat     = linux `cat` command, see `man cat`, displays file contents
{}      = placeholder for the currently found filename
\;      = tell `find` command that it ends now here

您还可以通过布尔运算符组合搜索,如-and或-or。找到-ls也很好。

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

试试这个

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

希望这能有所帮助

X 7.1泡芙

... 对我们中的一些人来说,抓住那些已经提到的头脑的人是有用的:

$ r head
head file*.txt
==> file1.txt <==
xxx
111

==> file2.txt <==
yyy
222
nyuk nyuk nyuk

==> file3.txt <==
zzz
$

我需要读第一行;如上所述,如果你想要超过10行,你必须添加选项(head -9999,等等)。

抱歉,我发表了一个衍生的评论;我没有足够的街头信誉来评论别人的评论。