2011-10-28 23 views
1

我有一個輸出文件的目錄,我想顯示每個文件的第一行和每個文件的最後十行訂購。頭和尾巴 - 試圖獲得每個文件的第一行和最後十行

我已經得到了命令下來的一部分:

ls output/*Response | sort -t_ --key=2 -g | xargs tail | less 

這給了我這樣的事情:

==> output/Acdb_18_Response <== 
150707,"SOVO","Other","","","","","","160x600",0,0,1432,0,0,1432 
167493,"Asper","Other","","","","","","160x600",143200,0,0,1432,0,0 
269774,"AIKA","Other","","","","","","160x600",0,1432,0,0,1432,0 
342275,"Lorrum","Other","","","","","","160x600",0,0,1432,0,0,1432 
347954,"Game","Other","","","","","","160x600",0,1432,0,0,1432,0 
418858,"Technologies","Other","","","","","","160x600",0,1432,0,0,1432,0 
24576,"Media ","Other","","","","","","300x600",0,0,1432,0,0,1432 
23351," Plus","Other","","","","","","425x600",0,4296,0,0,4296,0 
#rowcount=79 

這是很好的,但我想包括第一線得到標題。我試着開始輸出,但到目前爲止,我還沒有弄清楚如何安排管道。

有什麼建議嗎?

回答

2
ls output/*Response | sort -t_ --key=2 -g \ 
    | xargs -I {} sh -c 'head -1 {}; tail {}' | less 
0

您也可以嘗試以下方法:

ls output/*Response | sort -t_ --key=2 -g | ((head -n 1) && (tail -n 10)) | less 
相關問題