将多个CSV文件添加到新文件?
问题描述:
我有2个文件:testfile1.csv和testfile2.csv。将多个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
答
从手册(man tail
):
-q Suppresses printing of headers when multiple files are being examined.
因此,命令将是:
tail -qn +2 test1/testfile1.csv test2/testfile2.csv >> testfile3.csv
啊,我看到。感谢'-q'的解释。 – jxn