I want to convert the following matrix below Format 1), into the format in 2) with 4 column format going downwards, I am using the following perl code to do it and it works but is ugly. Can someone show me how is the proper way of doing it in perl. Thank You. Dave
Format 1)
A C F
SampleID Time ObsConc ObsConc ObsConc
5 24 2.27E+06 687.02 32521.94
5 168 1.92E+06 525.02 22198.44
5 12 2.94E+06 896.39 41331.61
5 -0.5 2.23E+06 942.34 40616.49
5 8 4.03E+06 1371.32 45863.69
6 24 1.02E+06 1057.89 46341.04
6 168 3.14E+06 4987.32 42166.08
Format 2) A 5 24 2.27E+06 A 5 168 1.92E+06 A 5 12 2.94E+06 A 5 -0.5 2.23E+06 A 5 8 4.03E+06 A 6 24 1.02E+06 A 6 168 ... C 5 24 ... C 5 168 ... C 5 12 ... C 5 -0.5 ... C 5 8 ... C 6 24 ... C 6 168 ... F 5 24 ... F 5 168 ... F 5 12 ... F 5 -0.5 ... F 5 8 ... F 6 24 ... F 6 168 ... etc...
foreach (3..$count_columns){ $header=`cut -f1,2,$_ $file | head -n1`; chomp $header; $cmd="cut -f1,2,$_ $file | grep -P \'^\\w+\' | grep -P -v \'^Sample +\' > $file\.2"; system($cmd); $cmd="perl -pi -e s\'/^/$header\\t/g\' $file\.2"; system($cmd); }
In reply to format conversion, please help by david_lyon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |