Fak*_*ada 3 linux full-text-search sed
我想创建一个sed命令,在文件中查找匹配模式的第一行,删除所有该行或将其全部替换为其他文本.我不想匹配所有的行,因为规则是匹配它的一部分.
我怎么能用sed做到这一点?
例如:
myline 1 is pretty
line 2 is ugly
myline 111 is nice
Run Code Online (Sandbox Code Playgroud)
我想删除包含"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
Run Code Online (Sandbox Code Playgroud)
如果您不使用GNU sed,请查看常见问题解答中的备选方案.