小编ins*_*246的帖子

如何将不以特定模式开头的行连接到UNIX中的上一行?

请查看下面的示例文件和所需的输出,以了解我在寻找什么。

可以通过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 bash shell awk sed

4
推荐指数
2
解决办法
2784
查看次数

Unix中grep -B/-A选项的替换/等价物是什么?

由于Unix不提供grep -A或者-B选项,我正在寻找在Unix中实现相同结果的方法.目的是打印所有不以特定模式和前一行开头的行.

grep -B1 -v '^This' Filename

这将打印所有不以字符串'This'和前一行开头的行.不幸的是我的脚本需要在Unix上运行.任何解决方法都会很棒.

bash grep posix

0
推荐指数
1
解决办法
245
查看次数

标签 统计

bash ×2

awk ×1

grep ×1

posix ×1

sed ×1

shell ×1

unix ×1