buccaneers
Programmer
Hello Gurus,
One question if i may ask.
In a flat file the record is as follows.
ab c ~~ efg ~~ hij ~~ klm
i assigning it to array in ksh in the format specified below
ab c
efg
hij
klm
i am able to achieve this by using following
tbldata[0]=`nawk '{ FS = "\~\~" } ; { print $1 }' flnme.out`
tbldata[1]=`nawk '{ FS = "\~\~" } ; { print $2 }' flnme.out`
tbldata[2]=`nawk '{ FS = "\~\~" } ; { print $3 }' flnme.out`
tbldata[3]=`nawk '{ FS = "\~\~" } ; { print $4 }' flnme.out`
What i am trying to do is to write a for loop where i can put the value of variable instead of $1,$2 etc.
below is the for loop i wrote but it spooled out an error and mentioned below.
t=4
s=0
while [ $s -lt $t ]
do
u=`expr ${s} + 1`
echo $u
tbldata[$s]=`nawk '{ FS = "\~\~" } ; { print $u }' flnme.out`
s=`expr ${s} + 1`
done
this reports the error as
1
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
2
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
3
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
4
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
Would appreciate if any one can help me in this ?
TIA
One question if i may ask.
In a flat file the record is as follows.
ab c ~~ efg ~~ hij ~~ klm
i assigning it to array in ksh in the format specified below
ab c
efg
hij
klm
i am able to achieve this by using following
tbldata[0]=`nawk '{ FS = "\~\~" } ; { print $1 }' flnme.out`
tbldata[1]=`nawk '{ FS = "\~\~" } ; { print $2 }' flnme.out`
tbldata[2]=`nawk '{ FS = "\~\~" } ; { print $3 }' flnme.out`
tbldata[3]=`nawk '{ FS = "\~\~" } ; { print $4 }' flnme.out`
What i am trying to do is to write a for loop where i can put the value of variable instead of $1,$2 etc.
below is the for loop i wrote but it spooled out an error and mentioned below.
t=4
s=0
while [ $s -lt $t ]
do
u=`expr ${s} + 1`
echo $u
tbldata[$s]=`nawk '{ FS = "\~\~" } ; { print $u }' flnme.out`
s=`expr ${s} + 1`
done
this reports the error as
1
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
2
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
3
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
4
nawk: illegal field $()
input record number 1, file flnme.out
source line number 1
Would appreciate if any one can help me in this ?
TIA