How to replace a few matches in one line using sed?
I have a file.log with text:
sometext1;/somepath1/somepath_abc123/somepath3/file1.a;/somepath1/somepath_abc123/somepath3/file1.o;/somepath1/somepath_abc123/somepath3/file1.cpp; sometext2;/somepath1/somepath_abc123/somepath3/file2.a;/somepath/somepath_abc123/somepath3/file2.o;/somepath1/somepath_abc123/somepath3/file2.cpp;
And I'm trying to replace somepath1/somepath_abc123/somepath3
in each line.
But unlikely the results is wrong:
sometext1;/mysomepath1/mysomepath2/mysomepath3/file1.cpp; sometext2;/mysomepath1/mysomepath2/mysomepath3/file2.cpp;
As you can see the sed returns only the last match.
I tried the following code:
#!/bin/sh FILE="file.log" OLD="somepath1\/somepath_.*\/somepath3" NEW="mysomepath1\/mysomepath2\/mysomepath3" sed 's|'"$OLD"'|'"$NEW"'|g' $FILE > $FILE.out
Whats wrong with the expression?