I need to replace commas (,
) with dots (.
) for the field containing numbers. My solution also replaces the dots in the date, which I do not want.
My starting point:
2020.01.02;2020-01-02;1.321;0.321;2.243;0.032
What I want:
2020.01.02;2020-01-02;1,321;0,321;2,243;0,032
This is what I managed to do, but it also changes the dot in the date to ,
:
$ sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/g' <file>
2020,01,02;2020-01-02;1,321;0,321;2,243;0,032
| |
`--`--dont want to replace these
I tried using ;
in the expression to narrow, but this gets me into problems of pattern matching:
| | | |
$ sed 's/;\([0-9]*\)\.\([0-9]*\);/;\1,\2;/g' eg
2020.01.02;2020-01-02;1,321;0.321;2,243;0.032
| |
` not replaced
Only every other .
is replaced.
Or
| |
sed 's/\([0-9]*\)\.\([0-9]*\);/\1,\2;/g' eg
2020.01,02;2020-01-02;1,321;0,321;2,243;0.032
|
` do not replace this
Any hints or tips are greatly appreciated!