I would like to use awk to edit a .csv-file with different type of values, for example round all values of several distinct columns to the second decimal place. The other rows may contain float-values as well, but those shall be handled in a different way.
Assuming one row looks like the one below and I would like to edit the 7th, 8th, and 9th column (in fact they are much longer, but all relevant type of values are in this example, so it's just a matter of scale):
L ,P_005 ,250.092 ,20.0 ,-0.80 ,0.803443 ,0.23342 ,0.83728329 ,0.0 ,0.0
The output should be
L ,P_005 , 250.092, 20.0, -0.80, 0.80, 0.23, 0.84, 0.0, E2=0.0
Up to now I've always round the value of one column "x" using:
#/bin/sh
OLDIFS=$IFS
IFS = ","
file=$1
...
awk '{printf "%.2f",$x}' $1
...
IFS=$OLDIFS
So how do I adapt this concept in a way, where I can
- edit multiple columns and
- display the entire csv-file
without writing down each column with a specific option?
{}editor button for your script, input, and output. What you have shown as the script you currently use is not valid awk syntax - please don't show us one thing and tell us it's something else as that just obfuscates your question and makes it harder for us to help you.