Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message for ARGV[2]????

Status
Not open for further replies.

csd

Programmer
May 10, 2001
6
US
I used ARGVs for a awk program and it worked well but
it always had some messages like this:

"awk: Cannot find or open file abc...
....The file is abc..."

The command for the awk job I used was
awk -f test.awk test.txt abc

Here, ARGV[0] should be awk, [1] test.txt, which is indeed a file, but ARGV[2]=abc is not a file.
If I print ARGV[2] in the awk, it's really abc...and it could be used in the awk program for data processing...
It looked like just a warning message because everything
else is fine, any idea?

Thanks.
csd
 
My question also is:
If it's just a warning message, is there any way I can
avoid it to appear?
Thanks.
csd
 
Hi csd,

Try this:

awk -f test.awk test.txt -v var="abc"

replacing var with whatever variable name you want
to use in your awk script.

You may also want to use nawk instead of awk if you
have it on your machine.

Gawk ( GNU awk ) will also work if you have it.

HTH


flogrr
flogr@yahoo.com

 
Hi csd,

I think you're trying to pass arguments into the awk script right?

Try this if you're passing arguments into the awk script:
awk -f awkscript argName=argValue inputfile

So in your case:
awk -f test.awk song=abc test.txt

You can have as many args as you like, but they should be placed before the inputfile argument. Their values also must not contain spacing. The argument that you passed into the awk script can be accessed directly using the argument's name.

Hope the explanations will help you.

ruxshin
 
ruxshin and flogrr:

I have already tested ruxshin's suggestion. I used 25 argvs, which are needed for my project, the job worked very good and the screen was very "cean": There was no warning message on it.

I think flogrr's way would also work and i will have time to test it later...
Great thanks to both of you.


csd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top