- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk format 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
06-08-2007 12:13 AM
06-08-2007 12:13 AM
node1_name:lan0:1.1.1.1
node1_name:lan1:2.1.1.1
node2_name:lan0:1.1.1.2
node2_name:lan1:2.1.1.2
So far when it comes to awk all I'm good for is pattern matching. :) Sorry, I don't need it in perl for all the perl gurus out here.
This should be some easy points for someone.
Thanks!
-denver
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 12:43 AM
06-08-2007 12:43 AM
Re: awk format help
Here is how I'd extact.
Data is in a file say
while read -r data
do
nodename=$(echo $data | awk -F: '{print $1}'
lannumber=$(echo $data | awk -F: '{print $2}'
ipaddy=$(echo $data | awk -F: '{print $3}'
done < file
Not the most efficient code but brutally effective.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 12:52 AM
06-08-2007 12:52 AM
Re: awk format help
I'm taking the output of cmgetconf and want to pull the node name, lan and ip for each heartbeat ip defined.
awk '/\ HEARTBEAT_IP|\ NETWORK_INTERFACE|NODE_NAME/&&!/^#/{print $NF}' /tmp/cmgetconf.out
Above awk gets me this...
node1_name
lan0
1.1.1.1
lan1
2.1.1.1
node2_name
lan0
1.1.1.2
lan1
2.1.1.2
But what I really want is the output format to be...
node1_name:lan0:1.1.1.1
node1_name:lan1:2.1.1.1
node2_name:lan0:1.1.1.2
node2_name:lan1:2.1.1.2
I'm not sure what need to be done w/ awk to get it there.
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:00 AM
06-08-2007 01:00 AM
Re: awk format help
This little awk script is based on cmgetconf output I found on the web, so I'm not sure that it will work for your data...
/^NODE_NAME/ {
nn=$2
}
/^NETWORK_INTERFACE/ {
ni=$2
}
/^STATIONARY_IP/ {
si=$2
comp=1
}
comp {
printf("%s:%s:%s\n",nn,ni,si)
comp=0
}
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:00 AM
06-08-2007 01:00 AM
Re: awk format help
awk '/ HEARTBEAT_IP/ print name ":" int ":" $NF} /NETWORK_INTERFACE/{int=$NF} /{name=$NF} |NODE_NAME/&&!/^#/{print $NF}' /tmp/cmgetconf.out
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:02 AM
06-08-2007 01:02 AM
Re: awk format help
awk '/^HEARTBEAT_IP/ print name ":" int ":" $NF} /^NETWORK_INTERFACE/{int=$NF} /^NODE_NAME/{name=$NF}' /tmp/cmgetconf.out
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:08 AM
06-08-2007 01:08 AM
Re: awk format help
To make up, some matching hints:
By testing for /^word/ we force the begin-of-line anchor, making the matching process quicker, and making commented lines not match.
You may want to use /^ *word/ to allow for zero or more spaces before the word, but still at line start.
An other way to deal with comments is to have the FIRST check be:
/ *#/ { next }
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:19 AM
06-08-2007 01:19 AM
Re: awk format help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2007 01:35 AM
06-08-2007 01:35 AM
Re: awk format help
Also to spex for running his example against my cmgetconf output, it's what I was looking for.
-denver