Operating System - HP-UX
1754043 Members
3188 Online
108811 Solutions
New Discussion юеВ

awk changed/fails at 11.31 vs. 11.23

 
SOLVED
Go to solution
Craig Johnson_1
Regular Advisor

awk changed/fails at 11.31 vs. 11.23

cat /home/oracle/check_agent.sh | awk '/first/ /second/ {{print $0}}'

11.23:

# cat /home/oracle/check_agent.sh | awk '/first/ /second/ {{print $0}}'
first_line=`awk 'NR == 101 { print $NF }' $LINE`
if [ "${first_line}" != "" ]; then
if [ $first_line != "" ]; then

11.31:

# cat /home/oracle/check_agent.sh | awk '/first/ /second/ {{print $0}}'
syntax error The source line is 1.
The error context is
/first/ /second/ >>> { <<<
awk: Quitting
The source line is 1.


Help! I'm no awk programmer - this is a customer's script.
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor
Solution

Re: awk changed/fails at 11.31 vs. 11.23

Hi Craig:

At the moment, I don't have an 11.23 box handy to check, but the syntax you show isn't correct.

Depending on what you want, do either:

# awk '/first|second/ {print $0}' file

...which prints lines that match *either* "first" or "second"; or:

# awk '/first/,/second/ {print $0}' file

...which prints all lines between ones matching "first" and then "second".

Regards!

...JRF...
Craig Johnson_1
Regular Advisor

Re: awk changed/fails at 11.31 vs. 11.23

Thanks James. That solved it. Your syntax works perfectly on both 11.23 and 11.31!

Re: awk changed/fails at 11.31 vs. 11.23

What I don't understand is why the syntax you had worked OK on 11.23 (or 11.11)

I tried it on 11.11 and it does work - I can't find any reference to this sort of syntax on the man pages - one wonders if it was an old syntax which was deprecated or simply a bug which some folks have exploited and is now fixed...

Duncan

I am an HPE Employee
Accept or Kudo
Craig Johnson_1
Regular Advisor

Re: awk changed/fails at 11.31 vs. 11.23

I was wondering the same thing.
Steven E. Protter
Exalted Contributor

Re: awk changed/fails at 11.31 vs. 11.23

Shalom,

awk performs operations for me on 11.11 11.23 and 11.31 consistently.

I would assume you have run into a defect resolved by patching. Most likely a relatively current QPK will do the trick.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Craig Johnson_1
Regular Advisor

Re: awk changed/fails at 11.31 vs. 11.23

A QPK for 11.23 or 11.31?
James R. Ferguson
Acclaimed Contributor

Re: awk changed/fails at 11.31 vs. 11.23

Hi (again):

> A QPK for 11.23 or 11.31?

I think neither. In my opinion, Duncan offers the explanation. This was probably a clean-up of a "bug" when 11.31 was rolled out.

For cases like this, you can look to the Patch database for the particular release (e.g. 11.23) and a patch applicable to 'awk'. The patch notes *might* offer insight in cases like this.

That said, your syntactically incorrect code failed to follow the correct 'pattern-action' syntax of 'awk'.

Regards!

...JRF...

Re: awk changed/fails at 11.31 vs. 11.23

SEP,

Not a patch issue I think - it was the first thing I thought of, and I didn't find anything appropriate in any awk patch README files - are you saying you *ran* this awk code successfully and un-modified on a 11.31 system?

If you did, then I'd like to see an output of:

what /usr/bin/awk

from that system...

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Dennis Handly
Acclaimed Contributor

Re: awk changed/fails at 11.31 vs. 11.23

>Duncan: simply a bug which some folks have exploited and is now fixed.

Most likely. It seems it used to do: /first/ || /second/
Or JRF's: /first|second/

The closest fix I can find is the Unix 2003 branding fix: QXCR1000530363