Hello all,
Having an ongoing battle with manipulating a string of numbers. I need to multiply all columns except 1 & 2 by 100 and output all columns except 2 in whole numbers as below.
If I have a file with
FNUM,SET,C1N,C2N,C3N,C1S,C2S,C3S,
4535, 109, 5.0709, 5.1546, 5.2002, 304.4215, 315.4393, 299.0198,
4536, 109, 5.1311, 5.2059, 5.2861, 282.5050, 295.5363, 288.6789,
4537, 109, 4.7416, 4.9326, 5.1422, 305.3368, 316.0573, 297.5717,
and I want an output in the form
FNUM C1N C2N C3N C1S C2S C3S
4535 507 515 520 30442 31543 29901
4536 513 520 528 28250 29553 28867
4537 474 493 514 30533 31605 29757
I can use
Quote:
in csh:
awk '{if(NR!=1) printf("%-6d%-6d%-6d%-6d\t%-6d%-6d%-6d\n",$1,($3*100),($4*100),($5*100),($6*100),($7*100),($8*100))}' $rfile > ${set}_tmp
or in perl:
system "awk \'{if(NR!=1) printf(\"%-6d%-6d%-6d%-6d\t%-6d%-6d%-6d\\n\",\$1,(\$3*100),(\$4*100),(\$5*100),(\$6*100),(\$7*100),(\$8*100))}\' $file > ${seq}_rtmp";
|
The problem is, every time I have a file with a different number of C values I have to change the script.
I want to be able to be able to use the script to do the same thing regardless of the number of columns without having to change the script every time. So if i had a file with 4 "C" values:
FNUM,SET,C1N,C2N,C1S,C2S,
4535, 109, 5.0709, 5.1546, 304.4215, 315.4393,
4536, 109, 5.1311, 5.2059, 282.5050, 295.5363,
4537, 109, 4.7416, 4.9326, 305.3368, 316.0573,
I could use the same script and get:
FNUM C1 C2 C1 C2
4535 507 515 30442 31543
4536 513 520 28250 29553
4537 474 493 30533 31605
Can anyone show me how to do this in shell or in perl?
Many thanks,
M.