Issue
I have a csv with a weird format, I would like to change decimal values by a point and keep the comma as separator. The issue is that sometimes I have 3 commas and sometimes 4 commas.
For example:
30,-4,098511E-02
30,05,-4,098511E-02
66,7,-1,865433
I need to transform to:
30,-4.098511E-02
30.05,-4,098511E-02
66.7,-1.865433
I don't know if that's possible to do it with sed or awk.
I tried something like sed -i 's/\(([0-9]+,?){1,2}),/\1./g' P7.csv > P7_test.csv
with no success
Solution
Assuming you know there are only 2 columns and the second column is always a floating-point number (when there are any), you can use this:
awk -F, 'NF == 3 { $0 = $1FS$2"."$3 } NF == 4 { $0 = $1"."$2FS$3"."$4 } 1' infile
Answered By - Thor Answer Checked By - Katrina (WPSolving Volunteer)