请查看下面的示例文件和所需的输出,以了解我在寻找什么。
可以通过shell脚本中的循环来完成,但是我在努力获得一个awk/ sed班轮。
SampleFile.txt
These are leaves.
These are branches.
These are greenery which gives
oxygen, provides control over temperature
and maintains cleans the air.
These are tigers
These are bears
and deer and squirrels and other animals.
These are something you want to kill
Which will see you killed in the end.
These are things you must to think to save your tomorrow.
Run Code Online (Sandbox Code Playgroud)
所需的输出
These are leaves.
These are branches.
These are greenery which gives oxygen, …Run Code Online (Sandbox Code Playgroud) 由于Unix不提供grep -A或者-B选项,我正在寻找在Unix中实现相同结果的方法.目的是打印所有不以特定模式和前一行开头的行.
grep -B1 -v '^This' Filename
这将打印所有不以字符串'This'和前一行开头的行.不幸的是我的脚本需要在Unix上运行.任何解决方法都会很棒.