From: Mills, John T (John.T.Mills@ERAC.COM)
Date: Tue Feb 18 2003 - 15:39:51 EST
All,
I got the solution from another source. The
script below can be replaced with a single
command:
echo $line | awk '{for (i=1; i<NF; i+=7) print $i,$(i+2),$(i+5)}'
Thanks,
John T. Mills
-----Original Message-----
From: Mills, John T
Sent: Tuesday, February 18, 2003 12:44 PM
To: IBM AIX Discussion List
Subject: Awk, print, printf question
All,
I am trying to variablize the print portion
of the awk command. The reason for this is
processing a variable length string. The
string will be 7 fields long, and I need fields
1, 3, and 6 respectively. The set would be as
follows:
1 3 6
8 10 13
15 17 20
...
NNET is the number of sets of 7 in the string
#############################################
i=1
FACTOR=0
while [ "$NNET" -ge "$i" ]
do
let k=1+$FACTOR
let l=3+$FACTOR
let m=6+$FACTOR
echo $line | awk {'print $$k,$$l,$$m'}
let FACTOR=$i*7
let i=$i+1
done
#############################################
Thanks,
John T. Mills
This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:36 EDT