1827857 Members
1654 Online
109969 Solutions
New Discussion

Re: Persistant awk error

 
debian111
Regular Advisor

Persistant awk error

Hi

I have this two lines of awk code in some script awk '{FS="|"}

awk 'BEGIN { print " some text for test purposes " }'
Script only should print " some text for test purposes " ... that is only requrement on this script....

when I run this script I got an error like below

awk: Syntax error at source line 2

awk: Context is

awk >>> BEGIN <<<

awk: Missing }

awk: Bailing out at source line 2

And no I am not able to figure out what could be a possible reason for this error.
It would be help me a lot if someone know and have free time and will to write down what I should change in order to make this works.

Thanks
1 REPLY 1
Ivan Ferreira
Honored Contributor

Re: Persistant awk error

You dont need BEGIN and END declarations:

The script could be like this:

cat awk.script

{ print "Some text" }

echo | awk -f awk.script

Remember that awk spect to precess something (a file or command output), that is why the echo is inserted.

What I did not understand is the FS="|" declaration, anyway you can declare variables like this:

BEGIN { FS=":" }
{ print "Username",$1, "UID", $3 }

awk -f /tmp/awk.script /etc/passwd
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?