Sally
Sally

Reputation: 91

How to replace arbritary combinations of (special) characters and numbers using sed and regular expressions

I have a csv file with nearly arbritary filled colums like this:

"bla","","blabla","bla::bla::blabla",19.05.16 12:00:03,123456789,"bla::38594f-47849-h945f",""

and now I want to replace the comma between the two numbers with a point:

"bla","","blabla","bla::bla::blabla",19.05.16 12:00:03.123456789,"bla::38594f-47849-h945f",""

I tried a lot but nothing helped. :-(

sed s/[0-9],[0-9]/./g data.csv

works but it delets the two numbers before and after the comma. So I tried things like

sed s/\(\.[0-9]\),\([0-9]\.\)/\1.\2/g data.csv

but that changed nothing.

Upvotes: 0

Views: 80

Answers (1)

AKS
AKS

Reputation: 19811

Try with s/\([0-9]\),\([0-9]\)/\1.\2/g:

$ echo '"bla","","blabla","bla::bla::blabla",19.05.16 12:00:03,123456789,"bla::38594f-47849-h945f",""' | sed 's/\([0-9]\),\([0-9]\)/\1.\2/g'
"bla","","blabla","bla::bla::blabla",19.05.16 12:00:03.123456789,"bla::38594f-47849-h945f",""

Regex Demo Here

You don't really need the additional dot \. in the capturing groups.

Upvotes: 1

Related Questions