AWK incrementing on column number

If by colN you mean the Nth column, your pseudocode straightforwardly translates to

awk '{ for(i=0; i<=9; ++i) $(30+i) = $(10+i) + $(20+i) }1'

Your dummy data looks like those are column labels in which case you have to parse the first line and figure out which column number corresponds to which label. For your example,

awk 'NR==1 { for(n=0; n<=NF; ++n) if ($n ~ "^col[123][0-9]$") a[$n]=n }
    { for(i=1; i<=9; ++i) a[30+i] = a[10+i] + a[20+i] }1'

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top