2015-11-05 73 views
0

我有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 

回答

0

從手冊(man tail):

 -q  Suppresses printing of headers when multiple files are being examined. 

因此,命令將是:

tail -qn +2 test1/testfile1.csv test2/testfile2.csv >> testfile3.csv 
+0

啊,我看到。感謝'-q'的解釋。 – jxn