1

when I call my awk script, I keep getting an error :

sam@sam-laptop:~/shell/td4$ awk -f agenda.awk -- -n Robert agenda.txt
awk: agenda.awk:6: printf "Hello"
awk: agenda.awk:6: ^ syntax error

the script contains this :

#!/usr/bin/awk
BEGIN {
}

printf "Hello"

END {
}

Thank you

1
  • with $awk -f agenda.awk agenda.txt it works fine, but i want to add command line arguments to my awk script.. so that my program searchs the agenda for a name with -n or an e-mail with -m... How do I do that ? Thank you ! Commented Mar 10, 2010 at 16:36

2 Answers 2

4

you need to wrap it in {}


BEGIN {
}
{
 printf "Hello"
}
END {
}

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thanks, but now i'm getting this error : awk: fatal: cannot open file `-n' for reading (No such file or directory)
i'm not sure what you are trying to do with the -- and -n Robert, but if you want to use agenda.txt as the source input just do: awk -f agenda.awk agenda.txt
with $awk -f agenda.awk agenda.txt it works fine, but i want to add command line arguments to my awk script.. so that my program searchs the agenda for a name with -n or an e-mail with -m... How do I do that ? Thank you !
adding arguments you use the "-v" option like so: awk -f agenda.awk -v name=Robert -v [email protected] agenda.txt
glad to help :-) awk is my favorite language
0

i think you also need to modify the shebang as

#!/usr/bin/awk -f

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.