1752436 Members
5737 Online
108788 Solutions
New Discussion юеВ

awk problem

 
Gemini_2
Regular Advisor

awk problem

when I run

awk '/abc|cde/ END{ print "--->" $1}' file
awk: cmd. line:1: /abc|cde/ END{ print "--->" $1}
awk: cmd. line:1: ^ parse error

I got parse error...why?

hmmm..

thank u
16 REPLIES 16
James R. Ferguson
Acclaimed Contributor

Re: awk problem

Hi:

This works for me as written (and I cut-and-pasted from this post).

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: awk problem

I don't see anything wrong at all. Is this HP-UX?
If it ain't broke, I can fix that.
Rodney Hills
Honored Contributor

Re: awk problem

It ran ok on my system.

Could you have an unprintable character in the command?

Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: awk problem

Is it possible you have "awk" aliased to something else?

Enter "alias" and look to see if awk is defined.

Rod Hills
There be dragons...
Gemini_2
Regular Advisor

Re: awk problem

I dont think that I have any unprintable characters..

very change.....

I am using linux system, does it matter?

awk is just awk right?
Rodney Hills
Honored Contributor

Re: awk problem

For the most part. awk is awk.

The history of awk includes a version called "new awk" or "nawk", then you have the gnu version.

Although your line is very simple and should be runable. Try replacing the "--->" with just "###". In case the ">" is being processed by awk for file redirection.

Rod Hills
There be dragons...
James R. Ferguson
Acclaimed Contributor

Re: awk problem

Hi (again):

Well, 'awk' is 'awk' just like UNIX is UNIX. There *ARE* variations. You might see if you have a "new" awk --- 'nawk'.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: awk problem

No awk is not just awk. The Gnu awk which is almost certainly your Linux version. The nawk (new awk - at least 20 years old which is HP-UX} and there is oawk (old awk) oawk is 'awk' on Solaris; nawk is awk on HP-UX; and gawk is awk on Linux.

I suspect that if you remove the 'END' your script will run.
If it ain't broke, I can fix that.
Gemini_2
Regular Advisor

Re: awk problem

Yes, if I took out "END", it will run, but I need END to do OFS=":"

gawk '/abc|cde/ END { OFS=":", print "**" $1}' file

thank you for trying...
maybe gnu awk works funny..