For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2006 > AWK....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author AWK....
nitikamehta23@gmail.com

2006-09-13, 3:56 am

$2 contains "abc:def"
while [ 1]
do
count=0
status[$count]=`echo "$2" | awk -F: '{ print $count }'`

when we execute the above command status[1] should get "abc and
status[2] should get def...
but it does not work....can somebody advice.....

count=$((count+1));

---do soemthing.......

done

Ed Morton

2006-09-13, 7:56 am

nitikamehta23@gmail.com wrote:
> $2 contains "abc:def"
> while [ 1]
> do
> count=0
> status[$count]=`echo "$2" | awk -F: '{ print $count }'`
>
> when we execute the above command status[1] should get "abc and
> status[2] should get def...
> but it does not work....can somebody advice.....
>
> count=$((count+1));
>
> ---do soemthing.......
>
> done
>


This is the correct syntax for what you're trying to do:

status[$count]=`echo "$2" | awk -F: -v cnt="$count" '{ print $cnt }'`

See question 24 in the comp.unix.shell FAQ,
http://home.comcast.net/~j.p.h/cus-faq-2.html#24.

Having said that, the above script doesn't make sense because you're
setting count to zero every time round the loop and you don't need awk
to do what you want anyway. You should post a questioin to
comp.unix.shell asking for help on generally fixing the script.

Ed.
Loki Harfagr

2006-09-16, 6:56 pm

Le Wed, 13 Sep 2006 07:06:59 -0500, Ed Morton a écrit_:

> nitikamehta23@gmail.com wrote:
....[color=darkred]
....[color=darkred]
> This is the correct syntax for what you're trying to do:
>
> status[$count]=`echo "$2" | awk -F: -v cnt="$count" '{ print $cnt }'`
>
> See question 24 in the comp.unix.shell FAQ,
> http://home.comcast.net/~j.p.h/cus-faq-2.html#24.
>
> Having said that, the above script doesn't make sense because you're
> setting count to zero every time round the loop and you don't need awk
> to do what you want anyway. You should post a questioin to
> comp.unix.shell asking for help on generally fixing the script.


Yes, and now I just can't wait to see coming in comp.unix.shell
a post entitled "SHELL" ;D)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com