我在表格的第六行
any_string($mno,"<anything here>",$log);
run_abc_cmd($mno,"<anything here>",$log);我需要把上面的行替换成
any_string($mno,"<anything here>",$log);
run_abc_cmd($mno,"<anything here>",$log,"",10);给出这样的东西
:%s/\$log\);/\$log,\"\",10\);/g解决不了我的目的。这里我需要的是只在包含特定模式的行上将特定的模式替换为另一个模式(在上面的例子中是run_abc_cmd)。我能用vi中的替代品来做这个吗?
发布于 2013-11-26 12:18:17
这个怎么样:
:%s/^\(\s*run_abc_cmd([^)]*\)/\1,"",10/g为了稍微解释一下,regex \(captures\)任意行开始(^),有任意数量的空格字符,后面跟着run_abc_cmd(,直到结束括号。替换是\1:对已捕获的部分的引用;后面是您想要添加的额外位数。
发布于 2013-11-26 12:25:34
:%s/^run_abc_cmd.*,$log/&,"",10/&优于\1,因为它允许不使用(和)。
请注意,
:/^run_abc_cmd/s/,$log/&,"",10/仅在/bin/vi中使用时选择第一个匹配行(但它选择/bin/sed和/bin/ed中的所有匹配行)。
https://stackoverflow.com/questions/20216488
复制相似问题