2013-07-09 27 views
1

我有這種文件:如何在unix shell中顯示一行和排序文件?

TAB | STAT | RECORDS 
------------------------ 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 
TAB1 
DUPKEY 
26 

正如你可以看到有多個線條和他們是一樣的。我需要的是製作一種名爲report.dat的文件,輸出將是

TAB | STAT | RECORDS 
------------------------ 
TAB1 DUPKEY  26 

我該怎麼做?

回答

0
# print the first 2 lines 
sed 2q file 
# skip the first 2 lines, join 3 lines into 1, then get unique lines 
sed 1,2d file | paste - - - | sort -u 
TAB | STAT | RECORDS 
------------------------ 
TAB1 DUPKEY 26 

paste默認用製表符聯接

+0

好,謝謝,現在我嘗試 –

+0

它不工作。這條指令是在一段時間內的if條件內。可能是一個問題? –

+0

發佈您的代碼。 –

相關問題