Deja.Com Daily Digest: comp.lang.awk 1/1 
Author Message
 Deja.Com Daily Digest: comp.lang.awk 1/1

Hi,

Can someone show me how to get shell variables into an awk script.....

ex.
  set x=1

  awk '{print $x}'

In my script, awk is not getting the value of $x. I have tried a number of things, including preceding the $x with backslash to protect it from interpretation by awk, all to no avail.

Sincerely,

Siva

PS If you can also suggest a good Awk programming reference, I would be much obliged. Csh and Perl programming guides would be appreciated. I am looking for (1) a book that serves as an occasional reference for syntactical issues and (2) books that serve as tutorials for someone trying to learn the language.

--== Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.

 Sent via Deja.com http://www.*-*-*.com/
 Before you buy.



Fri, 17 May 2002 03:00:00 GMT  
 Deja.Com Daily Digest: comp.lang.awk 1/1

Quote:

>Hi,

>Can someone show me how to get shell variables into an awk script.....

>ex.
>  set x=1

>  awk '{print $x}'

awk '{print var; exit}' var="$x" infile

or

gawk -v var="$x" '{print var}' infile

read the man pages and the FAQ posted for this newsgroup.

man awk
man gawk

Chuck Demas
Needham, Mass.

Quote:

>In my script, awk is not getting the value of $x. I have tried a number of things, including preceding the $x with backslash to protect it from interpretation by awk, all to no avail.

>Sincerely,

>Siva

>PS If you can also suggest a good Awk programming reference, I would be much obliged. Csh and Perl programming guides would be appreciated. I am looking for (1) a book that serves as an occasional reference for syntactical issues and (2) books that serve as tutorials for someone trying to learn the language.

>--== Sent via Deja.com http://www.deja.com/ ==--
>Share what you know. Learn what you don't.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Fri, 17 May 2002 03:00:00 GMT  
 Deja.Com Daily Digest: comp.lang.awk 1/1
thanks charles,

what i wound up doing was writing the shell variable in question to a
temporary file and  then did something like the following:

awk -v siva=`cat xv` -F',' '{print $siva}' new3.log

where xv holds the contents of the variable in question.

YOUR SOLution of -v var="$shellvar" was a lot cleaner,

siva



Quote:


> >Hi,

> >Can someone show me how to get shell variables into an awk
script.....

> >ex.
> >  set x=1

> >  awk '{print $x}'

> awk '{print var; exit}' var="$x" infile

> or

> gawk -v var="$x" '{print var}' infile

> read the man pages and the FAQ posted for this newsgroup.

> man awk
> man gawk

> Chuck Demas
> Needham, Mass.

> >In my script, awk is not getting the value of $x. I have tried a

number of things, including preceding the $x with backslash to protect
it from interpretation by awk, all to no avail.
Quote:

> >Sincerely,

> >Siva

> >PS If you can also suggest a good Awk programming reference, I would

be much obliged. Csh and Perl programming guides would be appreciated.
I am looking for (1) a book that serves as an occasional reference for
syntactical issues and (2) books that serve as tutorials for someone
trying to learn the language.

Quote:

> >--== Sent via Deja.com http://www.deja.com/ ==--
> >Share what you know. Learn what you don't.

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

> --
>   Eat Healthy    |   _ _   | Nothing would be done at all,

>   Die Anyway     |    v    | That no one could find fault with it.


Sent via Deja.com http://www.deja.com/
Before you buy.


Fri, 17 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Deja.Com Daily Digest: comp.lang.apl 1/1

2. Deja.Com Daily Digest: comp.lang.apl 1/1

3. Deja.Com Daily Digest: comp.lang.clarion 1/1

4. Deja.Com Daily Digest: comp.lang.labview 1/1

5. Deja.Com Daily Digest: comp.lang.vhdl 1/1

6. Out of Office AutoReply: Deja.Com Daily Summary: comp.lang.awk 1/ 1

7. Out of Office AutoReply: Deja.Com Daily Summary: comp.lang.awk 1/ 1

8. Out of Office AutoReply: Deja.Com Daily Summary: comp.lang.awk 1/ 1

9. Out of Office AutoReply: Deja.Com Daily Digest: alt.lang.asm 1/1

10. Rule: Re: Deja.Com Daily Summary: comp.lang.clarion 1/1

11. Deja.Com Daily Summary: comp.lang.logo 1/1

12. Out of Office AutoReply: Daily Digest: comp.lang.python 1/2

 

 
Powered by phpBB® Forum Software