Print three columns with awk, then sets of three columns -


i want create number of files larger file, dividing columns. example, header of larger file looks this:

name chr position snp1a snp1b snp1c snp2a snp2b snp2c snp3a snp3b snp3c

and want create these files:

name chr position snp1a snp1b snp1c

name chr position snp2a snp2b snp2c

name chr position snp3a snp3b snp3c

i've been trying use awk, i'm bit of novice it, command reads:

for ((i=1; i<=440;i++)); awk -f printindivs.awk inputfile done 

where printindivs.awk is: {print $1 $2 $3 $((3*$i)+1) $((3*$i)+2) $((3*$i)+3))}

the output i'm getting suggests way of trying sets of 3 wrong: how can this?

thanks

you can simple awk script:

$ awk '{for(i=4;i<=nf;i+=3)print $1,$2,$3,$i,$(i+1),$(i+2) > ("out"++j)}' file 

the output files in out[1..n]:

$ cat out1 name chr position snp1a snp1b snp1c  $ cat out2 name chr position snp2a snp2b snp2c  $ cat out3 name chr position snp3a snp3b snp3c 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -