如果特定字符串(直到行尾)匹配,则删除vi编辑器中的行

时间:2015-03-31 06:19:53

标签: linux editor vi

在vi编辑器中,如果特定字符串匹配,则删除那些字符串直到行尾。 表示行是

"I found a good solution for my bill printing task and it is working properly for me."

和要检入文件的字符串是

"working properly"

比输出

"I found a good solution for my bill printing task and it is "

我知道如何删除文件中每行的最后一个字符,然后命令: - esc:%s /.$// g 但我必须一次又一次地发出这个命令。

2 个答案:

答案 0 :(得分:0)

只需将要匹配的字符串放在正则表达式的开头:

%s/working properly.*//

答案 1 :(得分:0)

我相信使用

%s/\<working properly.*//g

是合适的。它只匹配完整的单词。

例如:它会匹配正常工作但不能网络正常