Thread View: comp.lang.awk
4 messages
4 total messages
Started by Dan Zhang
Thu, 22 May 1997 00:00
passing shell variable containing many fields to awk
Author: Dan Zhang
Date: Thu, 22 May 1997 00:00
Date: Thu, 22 May 1997 00:00
39 lines
951 bytes
951 bytes
I try the following shell script, #!/bin/ksh ..... temp="1 123 123 123" nawk ' /testing/ {sub("{.*}", "'$temp'") } {print $0} ' test_file $ test {1 3 136 182 246 193} nawk: syntax error at source line 11 context is /manager/ { sub("{.*}", >>> "1 <<< nawk: illegal statement at source line 21 missing } missing ) Somehow it did not pass in $temp variable properly as a string. It only takes 1. Any idea? Thanks in advance, Dan -- +------------------------------------------------------------------+ | Dan Zhang | Phone: (847) 632-5641 | | CIG, Motorola, Inc. | Fax: (847) 632-2900 | | 1441 West Shure Drive | Pager: (847) 576-0295/16017 | | Bldg IL27, Room 1441-2-3G | SMTP: zhangdn@cig.mot.com | | Arlington Heights, IL 60004 | X400: CDZ006@email.mot.com | +------------------------------------------------------------------+
Re: passing shell variable containing many fields to awk
Author: james@sn.no (Jam
Date: Thu, 22 May 1997 00:00
Date: Thu, 22 May 1997 00:00
38 lines
712 bytes
712 bytes
In comp.lang.awk, article <338484DF.41C67EA6@cig.mot.com>, Dan Zhang <zhangdn@cig.mot.com> wrote: > I try the following shell script, > > #!/bin/ksh > > ..... > temp="1 123 123 123" > nawk ' > /testing/ {sub("{.*}", "'$temp'") } You could try reversing this -------^ so that it becomes { > {print $0} > ' test_file } ^----- and end the script with this? > > > $ test > {1 3 136 182 246 193} > nawk: syntax error at source line 11 > context is > /manager/ { sub("{.*}", >>> "1 <<< > nawk: illegal statement at source line 21 > missing } > missing ) > > Somehow it did not pass in $temp variable properly as a string. It > only takes 1. > > Any idea? James
Re: passing shell variable containing many fields to awk
Author: Ulf.Michaelis@he
Date: Thu, 22 May 1997 00:00
Date: Thu, 22 May 1997 00:00
42 lines
865 bytes
865 bytes
On Thu, 22 May 1997 12:39:43 -0500, Dan Zhang <zhangdn@cig.mot.com> wrote: >I try the following shell script, > >#!/bin/ksh > >..... >temp="1 123 123 123" >nawk ' >/testing/ {sub("{.*}", "'$temp'") } >{print $0} >' test_file > > >$ test >{1 3 136 182 246 193} >nawk: syntax error at source line 11 > context is > /manager/ { sub("{.*}", >>> "1 <<< >nawk: illegal statement at source line 21 > missing } > missing ) > >Somehow it did not pass in $temp variable properly as a string. It only >takes 1. > >Any idea? As mentioned earlier in this group the spaces divide the argument 'programm' into parts. Awk needs the programm als ONE single argument on the command-line. it would be better to export the variable and to use the builtin arry ENVIRON: export temp="1 123 123 123" nawk '/testing/ {sub("{.*}", ENVIRON["temp"]) } ... Ulf
Re: passing shell variable containing many fields to awk
Author: Ingvar Mattsson
Date: Fri, 23 May 1997 00:00
Date: Fri, 23 May 1997 00:00
43 lines
867 bytes
867 bytes
Dan Zhang <zhangdn@cig.mot.com> writes: > > I try the following shell script, > > #!/bin/ksh > > ..... > temp="1 123 123 123" > nawk ' > /testing/ {sub("{.*}", "'$temp'") } > {print $0} > ' test_file > > > $ test > {1 3 136 182 246 193} > nawk: syntax error at source line 11 > context is > /manager/ { sub("{.*}", >>> "1 <<< > nawk: illegal statement at source line 21 > missing } > missing ) > > Somehow it did not pass in $temp variable properly as a string. It only > takes 1. > > Any idea? Yes, variable expansion happens before "argument tokenization", so you can do stuff like: FOO="-f gnutt" mv $FOO bar #equivalent to ``mv -f gnutt barοΏ½οΏ½ mv "$FOO" bar #generates an error A solution would be to do: temp=1 2 3 4 5 6 7 8 9 nawk '...'"$temp"'...' //Ingvar (not _strictly_ an awk question, but, at least, answered)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads