awk multiple delimiters

Hi Folks,

This is the first time I ever encountered this situation

My input file is of this kind

cat input.txt

1 PAIXAF 0 1 1 -9 0 0 0 1 2 0 2 1 2 1
7 PAIXEM 0 7 1 -9 1 0 2 0 1 2 2 1 0 2
9 PAKZXY 0 2 1 -9 2 0 1 1 1 0 1 2 0 1

Till the sixth column (which is -9), I want my columns to be in the same way as the input.

After the sixth column, I want to merge every two columns till the end of line.

I have million columns.

my output will be

1 PAIXAF 0 1 1 -9 00 01 20 21 21
7 PAIXEM 0 7 1 -9 10 20 12 21 02
9 PAKZXY 0 2 1 -9 20 11 10 12 01

Thanks

Is this 6th column ALWAYS a -9

Hi Joeyg,

thanks for ur time.

It is fixed at -9 all the time across all records.

I am having this idea in this mind, but donno how to write it in code

awk '{{for columns 1 to 6, print $1 to $6} \t {for columns 7 till NF, print every two columns together}}' input > output
awk '{printf $1 " " $2 " " $3 " " $4 " " $5 " " $6;for (i=7;i<=NF;i+=2) {printf " " $i $(i+1)};printf "\n"}'

the first printf may be optimized.

1 Like

Worked like a charm delugeag.

I enhanced this way

awk '{printf $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t";for (i=7;i<=NF;i+=2) {printf "\t"$i $(i+1)};printf "\n"}' test