- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk difference (RE) between HP-UX and Linux
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2012 08:06 AM
01-16-2012 08:06 AM
hello,
i detect following awk difference between HP-UX and Linux SLES-11
i want to find a entry with RE :
file:
;;DB_DEF#field1#field2#FS#junk#junk#junk#junk
HPUX OK:
awk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (+DB_TOKEN) { print $1,$2,$3,$4 }' file
LINUX :
it found all other entries of the file, but not the exact entry .....
i think my RE is OK ? is it not a standard RE ?
when i change from " (+DB_TOKEN)" to "DB_TOKEN" it works for Linux.
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2012 09:25 AM
01-16-2012 09:25 AM
Re: awk difference (RE) between HP-UX and Linux
Hi
AWK syntaxes in different from HPUX and LINUX, there is nothing unusual in this behavior.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2012 07:04 PM
01-16-2012 07:04 PM
Re: awk difference (RE) between HP-UX and Linux
There are several versions of awk. Many years ago, HP replaced standard awl with nawk but left the name the same. And then there's gawk -- which may be named awk too.
Here are some useful references. The first explains a lot of the design differences, the second is a great cheat sheet.
http://www.catonmat.net/blog/awk-nawk-and-gawk-cheat-sheet/
http://www.catonmat.net/download/awk.cheat.sheet.pdf
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2012 09:27 PM
01-16-2012 09:27 PM
Re: awk difference (RE) between HP-UX and Linux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2012 12:57 AM
01-17-2012 12:57 AM
Re: awk difference (RE) between HP-UX and Linux
AWK syntaxes in different from HPUX and LINUX, there is nothing unusual in this behavior.
in my case : what is the right behavior ? HPUX or LINUX ?
i use due to this thread below a lot of RE of AWK,
in the last part of the thread are good examples of James and Dennis :
replace a string with "/" in a variable
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2012 02:11 AM
01-17-2012 02:11 AM
Re: awk difference (RE) between HP-UX and Linux
i think LINUX awk is gawk, also i tested HPUX gawk and with the info of the thread awk is nawk
Info about Version
LINUX: Version
awk -W version
GNU Awk 3.1.8
HPUX: Version
gawk -W version
GNU Awk 3.1.5
awk -W version isn't allowed in HPUX
Test of LINUX and HPUX, different using of RE (+ or .* )
LINUX: OK
DB_TOKEN=DB_DEF
awk -F'#' '$1 ~ /^.*'"${DB_TOKEN}"'$/ { print $1,$2,$3,$4 }' file
awk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (DB_TOKEN) { print $1,$2,$3,$4 }' file
awk -v DB_TOKEN="DB_DEF" -F# '$1 ~ DB_TOKEN { print $1,$2,$3,$4 }' file
LINUX: NOTOK
awk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (+DB_TOKEN) { print $1,$2,$3,$4 }' file
HPUX: OK
DB_TOKEN=DB_DEF
awk -F'#' '$1 ~ /^.*'"${DB_TOKEN}"'$/ { print $1,$2,$3,$4 }' file
/usr/local/bin/gawk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (DB_TOKEN) { print $1,$2,$3,$4 }' file
/usr/local/bin/gawk -v DB_TOKEN="DB_DEF" -F# '$1 ~ DB_TOKEN { print $1,$2,$3,$4 }' file
HPUX: NOT OK
/usr/local/bin/gawk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (+DB_TOKEN) { print $1,$2,$3,$4 }' file
regards
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2012 02:48 AM
01-17-2012 02:48 AM
Re: awk difference (RE) between HP-UX and Linux
i found a agreement between LINUX and HPUX :
awk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (".+"DB_TOKEN) { print $1,$2,$3,$4 }' file
OK ?
but the options of ERE of gawk isn't possible to use for awk HPUX like r{n,m} with possix :-((
Info:
[abc...] character list, matches any of the characters abc....
[^abc...] negated character list, matches any character except abc....
r1|r2 alternation: matches either r1 or r2.
r1r2 concatenation: matches r1, and then r2.
r+ matches one or more r's.
r* matches zero or more r's.
r? matches zero or one r's.
(r) grouping: matches r.
r{n}
r{n,m} One or two numbers inside braces denote an interval expression. If there is one
number in the braces, the preceding regular expression r is repeated n times.
If there are two numbers separated by a comma, r is repeated n to m times. If
there is one number followed by a comma, then r is repeated at least n times.
Interval expressions are only available if either --posix or --re-interval is
specified on the command line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2012 10:14 AM
01-17-2012 10:14 AM
Re: awk difference (RE) between HP-UX and Linux
...but the options of ERE of gawk isn't possible to use for awk HPUX like r{n,m} with possix :-((
The POSIX shell is no different than ksh or bash. Braces (and parenthesis and semicolons, etc) have special meaning to the shell and must therefore be excluded from shell processing. There is no problem at all if the awk statements are in an awk script, but on the command line, you must must single quotes (apostrophes) to turn off shell processing.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2012 10:31 AM
01-17-2012 10:31 AM
Re: awk difference (RE) between HP-UX and Linux
>awk -v DB_TOKEN="DB_DEF" -F# '$1 ~ (".+" DB_TOKEN) { print $1,$2,$3,$4 }' file
I assume this is required since you need to do string concatenation and you need that "." before the "+".
>but the options of ERE of gawk isn't possible to use for awk HP-UX like r{n,m} with POSIX
Do you have an example where it fails?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2012 09:32 PM
01-18-2012 09:32 PM
Solution>I think my RE is OK? Is it not a standard RE?
No, this is a bogus ERE, in that it most likely won't do anything useful.
>>I assume this is required since you need to do string concatenation and you need that "." before the "+".
Yes. This is the problem. Error recovery is different between the two versions of awk.
It appears HP-UX's version is broken. The Posix standard says to convert a string to a number it should use atof(3). Unfortunately it doesn't mention clearly if the string is bogus, you get 0.
You can see this if you change awk to add:
BEGIN { print "ERE:", (+DB_TOKEN) }
For HP-UX, it seems to ignore the unary "+" as do nothing and it prints: DB_DEF
For gawk, it honors unary "+" and converts the bogus string and prints: 0
So if you want your ERE to skip one or more chars, you need: (".+" DB_TOKEN)