- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk - script sequence problem?
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
Forums
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
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
12-02-2002 04:43 AM
12-02-2002 04:43 AM
awk - script sequence problem?
I have another little annoying niggle in awk.
I can get around the problem, but for future reference, I would like to know why. I have the following script :
run with
# my_awk_script
cat $1 | awk -F"|" '
$1 ~ /^249$/ {printf("%s|%s|%s|%s DAN HOWARD|\n",$1,$2,$3,$4);next}
/^DAN HOWARD|$/ {next}
/^Dan Howard|$/ {next}
{print $0}' >> modD0125_$1
what I am trying to do is make :
ZHV|
blah blah blah|1234|abcd|zzz,
DAN HOWARD|
blah blah blah|5678|efgh|zzz,
DAN HOWARD|
ZPT|
look like :
ZHV|
blah blah blah|1234|abcd|zzz, DAN HOWARD|
blah blah blah|5678|efgh|zzz, DAN HOWARD|
ZPT|
but when I use the above script, awk omits the
{print $0}
and I get the following :
blah blah blah|1234|abcd|zzz, DAN HOWARD|
blah blah blah|5678|efgh|zzz, DAN HOWARD|
(my header and footer is missing)
but if I use the following, everything works fine.
cat $1 | awk -F"|" '
$1 ~ /^249$/ {printf("%s|%s|%s|%s DAN HOWARD|\n",$1,$2,$3,$4);next}
$1 ~ /^ZHV$/ {print $0}
$1 ~ /^ZPT$/ {print $0}
/^DAN HOWARD|$/ {next}
/^Dan Howard|$/ {next}' >> modD0125_$1
it obviously has something to do with the ordering, but I can't see what (do pipe chars need to be escaped?)
any ideas?
thanks in advance!
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 05:14 AM
12-02-2002 05:14 AM
Re: awk - script sequence problem?
What the .... is this:
$1 ~ /^249$/
??
Is that a ctrl-249 then a $ sign ??
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 05:32 AM
12-02-2002 05:32 AM
Re: awk - script sequence problem?
John,
The issue I guess was your listed input of
ZHV|
blah blah blah|1234|abcd|zzz,
DAN HOWARD|
blah blah blah|5678|efgh|zzz,
DAN HOWARD|
ZPT|
Which contains no "249"'s.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 05:55 AM
12-02-2002 05:55 AM
Re: awk - script sequence problem?
My problem is that it seems to work on my system ... but your test case doesn't match your script (like first field equals 249), so perhaps I made something wrong in my program which makes it work ...
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 06:00 AM
12-02-2002 06:00 AM
Re: awk - script sequence problem?
I was using $1 ~ /^249$/ to match the first field ($1) of all rows that start (^) with the numeric 249 only (hence the (^ ....... $) to ensure I only get fields that are 249 alone and not 2491234, etc.
Jean,
Hmm strange, we are on HP-UX 11.00. I am a bit confused as to why it isn't working, It seems to only work one way on my machine (HP 'N' class), nevermind, at least I have a work around,
thanks for your responses guys
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 06:00 AM
12-02-2002 06:00 AM
Re: awk - script sequence problem?
If I change your "blah blah blah"'s to 249, then the script works:
# ./tyu uyt
ZHV|
249|1234|abcd|zzz, DAN HOWARD|
249|5678|efgh|zzz, DAN HOWARD|
ZPT|
# cat ./tyu uyt
#!/usr/bin/ksh
#
cat $1 | awk -F"|" '
$1 ~ /^249$/ {printf("%s|%s|%s|%s DAN HOWARD|\n",$1,$2,$3,$4);next}
/^DAN HOWARD\|$/ {next}
/^Dan Howard\|$/ {next}
{print $0}'
ZHV|
249|1234|abcd|zzz,
DAN HOWARD|
249|5678|efgh|zzz,
DAN HOWARD|
ZPT|
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 06:02 AM
12-02-2002 06:02 AM
Re: awk - script sequence problem?
here is an example file :
ZHV|
249|1100019210315|20021105|DAN HOWARD.|
249|1100000348295|20021105|DAN HOWARD.|
ZPT|
cheers
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2002 06:05 AM
12-02-2002 06:05 AM
Re: awk - script sequence problem?
that input doesn't work either.
ZHV|
249|1100019210315|20021105|DAN HOWARD.|
249|1100000348295|20021105|DAN HOWARD.|
ZPT|
??
live free or die
harry