使用 shell 脚本,我正在寻找一种使 grep 命令执行以下两个选项之一的方法:
a) 使用 grep 命令显示文件中匹配的以下 10 行;即,该命令grep "pattern" file.txt
将导致具有该模式的文件的所有行:
patternrestoftheline
patternrestofanotherline
patternrestofanotherline
...
所以我正在寻找这个:
patternrestoftheline
following line
following line
...
until the tenth
patternrestofanotherline
following line
following line
...
until the tenth
b) 使用 grep 命令显示两个模式中的所有行,就好像它们是限制一样
patternA restoftheline
anotherline
anotherline
...
patternB restoftheline
我不知道另一个命令而不是 grep 是否是更好的选择。我目前正在使用一个循环来解决我的问题,但是是逐行的,所以对于非常大的文件需要太多时间。
我正在寻找适用于 Solaris 的解决方案。有什么建议么?