我有文本文件。任务 - 之后从文件中获取第一行和最后一行
$ cat file | grep -E "1|2|3|4" | commandtoprint
$ cat file
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)
在没有 cat 输出的情况下需要这个(只有 1 和 5)。
~$ cat file | tee >(head -n 1) >(wc -l)
1
2
3
4
5
5
1
Run Code Online (Sandbox Code Playgroud)
也许存在 awk 和更短的解决方案......