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

发布于 2024-12-13 04:14:36 字数 852 浏览 2 评论 0原文

我有一个输出文件目录,我想按顺序显示每个文件的第一行和最后十行。

我已经得到了部分命令:

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

这很好,但我想包含第一行来获取标题。我尝试将输出连接到头部,但到目前为止我还无法弄清楚如何排列管道。

有什么建议吗?

I've got a directory of output files that I'd like to display the first line of each file and the last ten lines of each file in order.

I've got part of the command down:

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

Which give me something like this:

==> 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

which is nice but I'd like to include the first line to get the header. I tried tee'ing the output to head but so far I haven't been able to figure out how to arrange the pipes.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有伤那来痛 2024-12-20 04:14:36
ls output/*Response | sort -t_ --key=2 -g \
    | xargs -I {} sh -c 'head -1 {}; tail {}' | less
ls output/*Response | sort -t_ --key=2 -g \
    | xargs -I {} sh -c 'head -1 {}; tail {}' | less
月牙弯弯 2024-12-20 04:14:36

您还可以尝试以下操作:

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

You can also try the following:

ls output/*Response | sort -t_ --key=2 -g | ((head -n 1) && (tail -n 10)) | less
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文