【发布时间】:2016-02-06 19:16:06
【问题描述】:
我有 2 个文件:testfile1.csv 和 testfile2.csv。
testfile2.csv:
time,topic3,topic4
2015-10-01,40,50
2015-10-02,45,55
country,uk,uk
testfile1.csv:
time,topic1,topic2
2015-10-01,20,30
2015-10-02,25,35
country,usa,usa
我想将它们组合成 1 个大文件,测试文件 1 被复制并且只有 1 个标题,所以我这样做了:
cat test1/testfile1.csv > testfile3.csv
tail -n +2 test1/testfile1.csv test2/testfile2.csv >> testfile3.csv
除了显示哪组数据来自哪个文件的指示符之外,输出看起来正确:
time,topic1,topic2
2015-10-01,20,30
2015-10-02,25,35
country,usa,usa
==> test1/testfile1.csv <==
2015-10-01,20,30
2015-10-02,25,35
country,usa,usa
==> test2/testfile2.csv <==
2015-10-01,40,50
2015-10-02,45,55
country,uk,uk
如何删除指标?我写错了tail -n + 2 部分吗?
当我使用tail -n +2 test2/testfile2.csv >> testfile2.csv 时,输出看起来不错,但我不想逐个文件手动执行。
预期输出:
time,topic1,topic2
2015-10-01,20,30
2015-10-02,25,35
country,usa,usa
2015-10-01,20,30
2015-10-02,25,35
country,usa,usa
2015-10-01,40,50
2015-10-02,45,55
country,uk,uk
【问题讨论】: