【发布时间】:2021-11-14 07:25:34
【问题描述】:
我希望以这种方式格式化我的输出,但使用适当、更优雅的代码。
在文件中:
line with foo occurence
line with foo occurence
line with bar occurence
line with bar occurence
line with foo occurence
line with foo occurence
我的 bash 命令:
cat file | grep -e foo && printf '\n' && cat file | grep -e bar
结果:
line with foo occurence
line with foo occurence
line with foo occurence
line with foo occurence
line with bar occurence
line with bar occurence
【问题讨论】:
-
与
sed:sed -n '/foo/p; /bar/H; ${g; p}' file -
不错的@Cyrus ;-) 有一天我应该学习如何真正使用
sed循环和缓冲区