Replace a special character with another one in a string using Linux regex
Hi everyone,
I am trying to replace the first period by a hyphen in following strings by using regex (?<=\d\d)\.
12345.678910-68597-19_A250_M007_001_1_1.abcde.fg
I am using sed command as sed 's/(?<=\d\d)\./-/'
To make the output as follows:
12345-678910-68597-19_A250_M007_001_1_1.abcde.fg
However, in Linux its not working.
Can anyone help where I am making a mistake?
Thanks
• 1,271 views
•
link
1 answer
One possible solution is capturing the part before and after . and joining them with a -.
sed 's/^\([0-9]\+\).\(.*\)/\1\-\2/' <text>
• 0 views
•
link
Log in to answer this question.