Computing.Net > Forums > Programming > could I pass awk variable to shell?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

could I pass awk variable to shell?

Reply to Message Icon

Name: zhynxn
Date: July 4, 2006 at 08:54:22 Pacific
OS: FC5
CPU/Ram: 1G
Product: Fedora
Comment:

I wanna use a system function to deal with several data. So I use awk variable FILENAME to transfer the file directory to system command, but it does not work.

I use a shell function "out_function" to deal with data and save the result in another directory with the same file name.
How can I do it?
My code is as follows:
#try.awk

{system("./out_function FILENAME > ./dst/FILENAME")
print FILENAME
nextfile
}

I use command ---awk -f try.awk ./src/* --- to open data files. I found that system("
command") could not recongnize FILENAME, so it could not run correctly. How
ever, my test command--print FILENAME-- runs correctly.
How should I do to solve this problem? Thanks a lot.




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 5, 2006 at 09:30:37 Pacific
Reply:

You've embedded FILENAME in quotes so awk just treats it as another literal string. This example buils an execution string with FILENAME outside the quotes so it's treated as a variable:

awk ' {
str="./out_function " FILENAME " > /dst/"FILENAME
system(str)
} ' data.file


0

Response Number 2
Name: zhynxn
Date: July 5, 2006 at 21:10:44 Pacific
Reply:

thanks a lot.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: could I pass awk variable to shell?

VC++ passing variables to a button www.computing.net/answers/programming/vc-passing-variables-to-a-button/13507.html

VC++ passing variables to a button www.computing.net/answers/programming/vc-passing-variables-to-a-button-/13487.html

VB6 - Passing 2 vars to shell() www.computing.net/answers/programming/vb6-passing-2-vars-to-shell/16274.html