- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help with awk
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
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
04-24-2003 12:18 PM
04-24-2003 12:18 PM
awk -v ptnum=$portnum '($2 == "is" && $3 == "up")
{print "Port# " ptnum " Status: " $3 " Protocol: " $7;next}
($2 == "packets" && $3 == "input")
{print " Pkt In: " $1 " Byte In: " $4;next}
($2 == "input" && $3 == "errors,")
{print " IN Errs: " $1;next}
($2 == "packets" && $3 == "output")
{print " Pkt In: " $1 " Byte In: " $4;next}
($2 == "output" && $3 == "errors,")
{print " OUT Errs: " $1 "Collisions: " $4;next}
' $pfile
Can someone point out what I am doing wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2003 12:47 PM
04-24-2003 12:47 PM
Re: Help with awk
($2 == "packets" && $3 == "output")
need to be changed to
($2 == "packets" && $3 == "input,")
($2 == "packets" && $3 == "output,")
You left off trailing comma.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2003 01:03 PM
04-24-2003 01:03 PM
Re: Help with awk
I don't know what you've done - and am not going to debug your awk program - this is a neat way of doing this -
$ cat g.awk
/is up/ {print "Port# " ptnum " Status: " $3 " Protocol: " $7}
/packets input/ {print "Pkt In: " $1 " Byte In: " $4}
/packets output/ {print "Pkt Out: " $1 " Byte Out: " $4}
/output errors/ {print "Out Errors: " $1 " Collisions: " $4}
$ awk -v ptnum=$portnum -f g.awk $pfile
works with gnu awk for me.
HTH.
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2003 01:08 PM
04-24-2003 01:08 PM
Re: Help with awk
I think part of your problem is the use of 'next'. This causes you to stop processing the current record and begin with the next one. Any subsequent rules for the *current* record, in that case, are never executed.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2003 01:59 PM
04-24-2003 01:59 PM
Re: Help with awk
I think the use of "next" is ok here, because "next" in awk means don't do any more pattern matches on the current input line. The script starts from the top with the next record.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2003 03:38 AM
04-25-2003 03:38 AM
Re: Help with awk
Yes, you're correct (of course). I'm not sure what I was thinking!
Warmest Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2003 04:30 AM
04-25-2003 04:30 AM
SolutionAgain a new "feature" ... If you join line with patterns "(...)" and line with actions "{...}" it will work ... especially if you add trailings commas on all $3 patterns and change in to out on line 4.
Regards.
awk -v ptnum=$portnum '($2 == "is" && $3 == "up,") {print "Port# " ptnum " Status: " $3 " Protocol: " $7;next}
($2 == "packets" && $3 == "input,") {print " Pkt In: " $1 " Byte In: " $4;next}
($2 == "input" && $3 == "errors,") {print " IN Errs: " $1;next}
($2 == "packets" && $3 == "output,") {print " Pkt Out: " $1 " Byte Out: " $4;next}
($2 == "output" && $3 == "errors,") {print " OUT Errs: " $1 "Collisions: " $4;next}
' $pfile
/homeHA/phelix/tmp> sh a
Port# 0 Status: up, Protocol: up
Pkt In: 6771318 Byte In: 541384107
IN Errs: 56
Pkt Out: 7004964 Byte Out: 1791101868
OUT Errs: 0Collisions: 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2003 04:45 AM
04-25-2003 04:45 AM
Re: Help with awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2003 04:48 AM
04-25-2003 04:48 AM
Re: Help with awk
You need to escape the returns at the end of your match lines - this should work:
awk -v ptnum=$portnum '($2 == "is" && $3 == "up,"){print "Port# " ptnum " Status: " $3 " Protocol: " $7}
($2 == "packets" && $3 == "input,"){print " Pkt In: " $1 " Byte In: " $4}
($2 == "input" && $3 == "errors,"){print " IN Errs: " $1}
($2 == "packets" && $3 == "output,"){print " Pkt In: " $1 " Byte In: " $4}
($2 == "output" && $3 == "errors,"){print " OUT Errs: " $1 "Collisions: " $4}
' $pfile
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2003 04:51 AM
04-25-2003 04:51 AM
Re: Help with awk
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2003 05:21 AM
04-25-2003 05:21 AM
Re: Help with awk
Once the single quote opens the commands section of the awk no continuation characters are required. Awk looks at it as being a script and not as a bunch of single commands. Of course, the script ends with a closing single quote.