Tuesday, 6 August 2013

Combining columns within a single file using awk

Combining columns within a single file using awk

I am trying to reformat a large file. The first 6 columns of each line are
OK but the rest of the columns in the line need to be combined in
increments of 2 with a "/" character in between.
Example file:
1 1 0 0 1 2 A T A C
Into:
1 1 0 0 1 2 A/T A/C
So far I have been trying awk and this is where I am at...
awk '{print $1,$2,$3,$4,$5; for(i=7; i < NF; i=i+2) print $i+"/"+$i+1}'
myfile.txt > mynewfile.txt

No comments:

Post a Comment