Reputation: 31
Is it possible to make an awk program to run on a file without giving it the name of the file when you run the program.
i tried to do this but for some reason it does not work,can someone please explain why this does not work and how do i make it work
#!/bin/awk -f
BEGIN{
ARGV[1]="books"
}
{
split($0,a,":")
if(a[4]!="-"){
n[a[2]]=n[a[2]]+1
print $0","n[a[2]]
}
}
END{
for(x in n){
print n[x]
}
}
in this program i tried to make it run on a file name books but it still does not work
Upvotes: 2
Views: 107
Reputation: 74685
As well as adding an element to ARGV
, you need to increment ARGC
:
#!/bin/awk -f
BEGIN{
ARGV[1]="books"
++ARGC
}
From the GNU AWK manual:
Storing additional elements [in
ARGV
] and incrementingARGC
causes additional files to be read.
Upvotes: 5