我必须替换成千上万的包含“SomeWord-”的字符串,后跟四个数字(可以是任意四个数字)。
例如,该文件可能包含:
blah:"someValue1",
otherThing:"someOtherValue1",
importantThing:"SomeWord-1232",
etc:".....",
importantThing:"SomeWord-4567",
otherThing:"SomeWord-8438"
它需要成为另一个字符串:
blah:"someValue1",
otherThing:"someOtherValue1",
importantThing:"SomeOtherWord-ABC",
etc:".....",
importantThing:"SomeOtherWord-ABC",
otherThing:"SomeOtherWord-ABC"
使用sed,grep,vim等最简洁的方法是什么?
在Vim你可以做到
:%s/SomeWord-\d\+/SomeOtherWord-ABC/g
匹配一个或多个数字,如果你想要四个,那么你可以做
:%s/SomeWord-\d\{4}/SomeOtherWord-ABC/g