gpt4 book ai didi

string - 删除模式之后的所有内容,包括模式

转载 作者:行者123 更新时间:2023-12-01 15:42:23 25 4
gpt4 key购买 nike

我有一个像这样的文本文件

some
important
content
goes here
---from here--
some
unwanted content

我正在尝试删除 ---from here-- 之后的所有行包括 ---from here-- .也就是说,期望的输出是

some
important
content
goes here

我试过了 sed '1,/---from here--/!d' input.txt但它并没有删除 ---from here--部分。如果我使用 sed '/---from here--.*/d' input.txt , 它只是删除 ---from here--文本。

如何删除包含该模式的模式后的线条?

编辑

我可以通过执行第一个操作并将其输出通过管道传输到第二个操作来实现它,例如 sed '1,/---from here--/!d' input.txt | sed '/---from here--.*/d' > outputput.txt .
有一步解决方案吗?

最佳答案

另一种使用 sed 的方法:

sed '/---from here--/,$d' file

d(删除)命令应用于从包含 的第一行---从这里--- 到文件末尾的所有行($ )

关于string - 删除模式之后的所有内容,包括模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54520838/

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