Hi all,
I have a set of numbers under some headers in a file:
FNUM,BNUM,C1N,C2N,C3N,C1S,C2S,C3S,
4535, 109, 5.5955, 5.6523, 5.8084, 311.419, 295.2540, 286.9984,
4536, 109, 5.7667, 5.7174, 5.6771, 291.782, 285.0646, 271.5945,
4537, 109, 5.1433, 5.3641, 5.4985, 301.515, 312.0447, 293.8658,
I have a script to take columns 1, 3, 4, 5..8 multiply by 100 and output the result in a file.
Quote:
set file = $file.csv
# Use awk to correct the format and multiply by 100
awk '{if(NR!=1) printf("%-5d%-5d%-5d\t%-5d%-5d%-5d\n",$1,($3*100),($4*100),($5*100),($6*100),($7*100),($8*100))}' $file > newfile
|
Which will give me something like this (the numbers here aren't correct)
FNUM C1N C2N C3N C1S C2S C3S,
4535 1982 2002 1894 10918 9680 8698
4536 1865 1885 1883 11082 9592 8682
4537 1984 1972 9620 10940 8631 7653
I would like to have the script do this regardless of how many columns are in the file so if I had a file with 4CN and 4CS it would do the same thing to the extra columns.
FNUM,BNUM,C1N,C2N,C3N,
C4N,C1S,C2S,C3S,
C4S
4535, 109, 5.5955, 5.6523, 5.8084,
5.2584, 291.419, 295.2540, 286.9984,
294.6548,
4536, 109, 5.7667, 5.7174, 5.6771,
5.4984, 291.782, 285.0646, 271.5945,
284.5648,
I.e. it would ask for the number of columns in the file and output 9 columns (again these are just random numbers as an example):
FNUM C1N C2N C3N C4N C1S C2S C3S C4N
4535 1982 2002 1894 1918 9680 8698 1968 4984
4536 1865 1885 1883 1082 9592 8682 6959 5593
does anyone show me how to do this? (in shell or in perl)
Many thanks,
Michelle.