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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT:Pass awk variable to another program!!

Status
Not open for further replies.

Trancemission

Technical User
Oct 16, 2001
108
GB
I am looking to use AWK to split a line of text, then pass one of these variable to another program:

My line would look like:

Field1 Field2 2298 (the variable that I need to pass will be $3)

I need then to execute a program like:

/path/to/myprog 2298

I have been using AWK to print the variables but I can't get any further than that.

Cheers
 
How about

system("/path/to/myprog " $3)

CaKiwi
 
Sure, or:
a=$( awk '{print $3}' filename)
exec program $a
 
The way I am using awk is by piping the results of a grep:

grep 'LTD' /testing/customers|awk '{print $2}'

I have tried:

grep 'LTD' /testing/customers|a=$(awk '{print $2}')

But get unexpected error

Any ideas?
 
Does this work?

grep 'LTD' /testing/customers|awk '{system("/path/to/myprog $2")}'

Alternatively you could modify marsd's method like so

a=$( awk '/LTD/{print $2}' filename)
exec program $a


CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top