sed question
Hi All
I have a sed question I got the following (12121) and I want to replace the () with xxxx so the output would be xxxx12121 I am using the following but its not working sed 's/\(.*\)/xxxxxx/g' TMP4 > TMP5 emm Please help Thanks, Omar |
Hi, welcome to LQ,
try this one Code:
sed 's/[()]/xxxxxx/g' TMP1 > TMP2 Markus |
You need to capture the text inside the parentheses and repeat it in the replacement output. This requires regex backslash referencing.
Code:
sed -r 's/\((.*)\)/xxxxxx\1/g' TMP4 @markush; I don't think that will satisfy his requirements, as it will put the x's both before and after the string, when he seems to want it to be only before. |
Hi,
If you only want to substitute the ( and remove the ): sed -e 's/(/xxxx/g' -e 's/)//g' infile Hope this helps. EDIT: The above also works when there are more substitutions needed on one line. /EDIT. |
Hi (again),
This seems to work if there are numbers between the ( and ): sed -r 's/\(([0-9][0-9]*)\)/xxxxx\1/g' infile But as already stated by David the H., without an exact example of the input things might or might not work as expected. |
Quote:
Thanks alot this is working exactly as I want it to Omar |
Actually, probably the safest way to do it, without more info, would be this:
Code:
sed -r 's/\(([^)]*)\)/xxxxxx\1/g' infile. |
All times are GMT -5. The time now is 04:30 AM. |