unix Heads and Tails -尝试获取每个文件的第一行和最后十行

dy2hfwbg  于 2023-01-25  发布在  Unix
关注(0)|答案(2)|浏览(135)

我有一个输出文件的目录,我想按顺序显示每个文件的第一行和最后十行。
我已经记下了部分命令:

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

这是很好的,但我想包括第一行,以获得头部。我试图tee'ing输出到头部,但到目前为止,我还没有能够弄清楚如何安排管道。
有什么建议吗?

nvbavucw

nvbavucw1#

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

roejwanj2#

您还可以尝试以下操作:

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

相关问题