gpt4 book ai didi

bash - 将多个文件连接成一个没有标题的文件

转载 作者:行者123 更新时间:2023-11-29 09:31:00 25 4
gpt4 key购买 nike

我有三个 csv 文件(名称相同,例如 A_bestInd.csv),它们位于不同的子文件夹中。我想将它们全部复制到一个文件中(例如 All_A_bestInd.csv)。为此,我执行了以下操作:

{ find . -type f -name A_bestInd.csv -exec cat '{}' \; ; } >> All_A_bestInd.csv

此命令的结果如下:

Class   Conf        1   2   3   4 //header of file1
A Reduction 5 1 2 1
A Reduction 1 8 1 10
Class Conf 1 2 3 4 //header of file2
A No_red 2 1 3 2
A No_red 3 6 1 9
Class Conf 1 2 3 4 //header of file3
A Reduction 5 5 8 9
A Reduction 7 2 1 11

如您所见,问题是每个文件的标题都被复制了。如何更改我的命令以仅保留一个 header 并避免其余的?

最佳答案

使用 tail +2 修剪所有文件的标题。

find . -type f -name A_bestInd.csv -exec tail +2 {} \; >> All_A_bestInd.csv

要只保留一个 header ,您可以将其与 head -1 结合使用。

{ find . -type f -name A_bestInd.csv -exec head -1 {} \; -quit
find . -type f -name A_bestInd.csv -exec tail +2 {} \; } >> All_A_bestInd.csv

关于bash - 将多个文件连接成一个没有标题的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55892157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com