gpt4 book ai didi

sed 在多行模式前插入多行

转载 作者:行者123 更新时间:2023-12-04 04:48:12 24 4
gpt4 key购买 nike

我有以下很长的文件:

...
close unit 1
...
...
close unit 1
...
...
close unit 1

stop

我想在最后一个 close unit 1 之前插入多行这是之前的 stop .该文件包含未定义数量的 close unit 1 .

我在这里和那里发现了很多其他类似的问题,但答案对我没有帮助......例如我试过 https://stackoverflow.com/a/8635732/1689664但这没有用...

最佳答案

使用 sedtac :

$ tac inputfile | sed '/close unit 1/ {s/\(.*\)/\1\nLine3\nLine2\nLine1/; :loop; n; b loop}' | tac
...
close unit 1
...
...
close unit 1
...
...
Line1
Line2
Line3
close unit 1

stop

请注意,您需要在 sed 中以相反的顺序指定输入行。表达。

关于sed 在多行模式前插入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17856568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com