Replace a special character with another one in a string using Linux regex
1
0
Entering edit mode
21 months ago
eDNAuRNA ▴ 20

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

Linux regex • 322 views
ADD COMMENT
0
Entering edit mode
21 months ago

One possible solution is capturing the part before and after . and joining them with a -.

sed 's/^\([0-9]\+\).\(.*\)/\1\-\2/' <text>
ADD COMMENT

Login before adding your answer.

Traffic: 2493 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6