Addition of columns in a loop

I would like to add the numbers in 2nd column and 5th, 8th and 11th, and so forth till the end of the file then print them in one file.

Thanks,

So, johnkim0806

You've been a member for a year or so, so what have you tried so far?

  • Do you have some input?
  • Is there any suggestion on what numbers you want to insert?
  • What language would you prefer to use (perl, awk, ksh, bash....)

How about trying:-

while read c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
do
   echo "$c1 $RANDOM $c2 $c3 $RANDOM $c4 $c5 $c6 $c7 $RANDOM $c8 $c9 $c10 $RANDOM $c11"
done < inputfile > outputfile

It does what you ask, but it's a bit $RANDOM. :stuck_out_tongue:

You are not giving us much to go on.

Robin
Liverpool/Blackburn
UK