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

excuting saved awk script from command line 2

Status
Not open for further replies.

demis001

Programmer
Aug 18, 2008
94
US
I have a problem of feeding input file to saved awk script.

I want to save awk scirpt to a file and feed the file name from command line but do not work.
test.awk
---------------------------------------------
awk "{$1~/query|seq/}{a[$1]=$2}{print a["query"]"\t"a["seq"]"\t"}'
-------------------------------------------------------
chmod +x test.awk
$ ./test.awk inputefile
It doesn't work!!
if I do the following it will work
--------------------------------------------------
awk "{$1~/query|seq/}{a[$1]=$2}{print a["query"]"\t"a["seq"]"\t"}'inputfile
$./test.awk

But I don't want to edit the file every time I change the inputfile name

Dereje



 
test.awk:
awk '{$1~/query|seq/}{a[$1]=$2}{print a["query"]"\t"a["seq"]"\t"}' $*

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Another way:

Code:
#!/usr/bin/awk -f
{
    $1~/query|seq/
    a[$1]=$2
    print a["query"]"\t"a["seq"]"\t"
}

No need for braces around each line of code since they are all going to be executed for every line of input anyway.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top