gpt4 book ai didi

Linux SED 脚本找到匹配模式的第一行并将其删除

转载 作者:IT王子 更新时间:2023-10-29 01:03:22 30 4
gpt4 key购买 nike

我想创建一个 sed 命令以在文件中找到与模式匹配的第一行并删除所有该行或将其全部替换为其他文本。我不想匹配所有行,因为规则是匹配它的一部分。

我怎样才能用 sed 做到这一点?

例如:

myline 1 is pretty
line 2 is ugly
myline 111 is nice

我想删除包含“1 is”的第一行

更新:我的行可能有像“/”和“<”这样的字符

问候假

最佳答案

来自 sed FAQ :

sed '0,/RE/{//d;}' file        # delete only the first match
sed '0,/RE/s//to_that/' file # change only the first match

如果您不使用 GNU sed,请查看常见问题解答中的替代方案。

关于Linux SED 脚本找到匹配模式的第一行并将其删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6518810/

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