- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting help
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
01-04-2006 12:43 AM
01-04-2006 12:43 AM
I'm having some trouble trying to write a script that filters some information from an output...
On a HP-UX B11.00 OS, when I type netstat -rn, I get a full listing with lots of stuff. I want to filter the line that has the word "default" written on it, and get the exact text that's under the INTERFACE column, so I can get that interface name...
initially I tried:
netstat -rn | grep default | awk '{print $5}'
it works fine in some places, but there are others where INTERFACE is NOT the 5th column, so how can I write a script to identify what column INTERFACE is so I can properly use the AWK command, or if you have any other solutions, please help! Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2006 12:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2006 01:03 AM
01-04-2006 01:03 AM
Re: Scripting help
John's approach is valid, but you don't need the extra process of 'grep':
# netstat -rn | awk '$1~/^default/ {print $(NF-1)}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2006 01:14 AM
01-04-2006 01:14 AM
Re: Scripting help
definitely not too nice, but seems to work:
#!/usr/bin/sh
#Find Interface offset
a=`netstat -rn | grep ^Dest`
#Find start column of Interface
start=`expr index "$a" "I"`
# Extract the data from the default line
a=`netstat -rn | grep default | cut -c ${start}-`
# Find first space
start=`expr index "$a" " "`
# Display until first space
echo $a | cut -c -${start}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2006 01:19 AM
01-04-2006 01:19 AM
Re: Scripting help
See if this helps.
# netstat -rn | grep default | tr -s " " "\n" | grep lan
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2006 01:42 AM
01-05-2006 01:42 AM
Re: Scripting help
with a one line command:
netstat -rn | awk '$1~/^default/ {print $(NF-1)}'
HTH,
Art