- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to assign mutiple matches to variable
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
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
02-13-2012 08:25 AM
02-13-2012 08:25 AM
I have a report that I need to read and assign certain variable from each lineL
-
HOSTNAME: londewer
VioIP: 16.18.22.134
VioGW: 16.18.22.1
VioMask: 255.255.255.0
VioEn: en10 (ent10: =ent1, =ent3)
Man: man 7
CONS 16.18.21.201 is raider01
CONS16.18.21.202 is raider02
I want to search the host name and the values of CONS and print in a comma delimitted line ....
I am struggling with searching CONS so the above output I want to see
londewer:raider01:raider02
I am attempting to use awk with no avail
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2012 10:10 AM - edited 02-13-2012 10:11 AM
02-13-2012 10:10 AM - edited 02-13-2012 10:11 AM
Solution
Hello Lawrenzo,
- Are there multiple segments in the input file, or just one HOSTNAME and its attributes
- Is the spacing as erratic/unpredicatble as your example suggest?
I suggest you try this awk one-liner
$ awk '/HOSTNAME/{if (line != "") print line; line =$NF} /CONS/{line=line ":" $NF} END {print line}' < tmp.tmp
londewer:raider01:raider02
In slow motion:
/HOSTNAME/{ # if the line has HOSTNAME on it
if (line != "") print line; # if there was a line ready, then print it.
line =$NF} # start a new line, using the last field on the line.
/CONS/{ # if the line has the word CONS on it
line=line ":" $NF # append a colon and the last field to a current line.}
END {print line} # print the last (first!?) line built-up
IF you know for sure the match words have no spaces before them, then you shoudl 'anchor' the expressions like so: /^HOSTNAME/ and /^CONS/
If there is just one section, then the "if (line..." is superfluos
Enjoy!
Hein
btw... if this does NOT help you solve the problem, then please be sure to re-reply and ATTACH a realistic input example as .TXT file.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2012 12:11 AM
02-14-2012 12:11 AM
Re: how to assign mutiple matches to variable
Thank you Hein,
I will take a look at that now - and thanks for the "slow motion" it helps a lot.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2012 01:39 AM - edited 02-14-2012 01:40 AM
02-14-2012 01:39 AM - edited 02-14-2012 01:40 AM
Re: how to assign mutiple matches to variable
I even managed to hack around with the command and take a bit more input that is important not sure if its the best way but it works for me and gives me exaclty what I was looking for!
------------------------------
HOSTNAME: londew
ViosIP: x
ViosGW: x
ViosMask: 255.255.255.0
ViosEn: en10 (=en1, =en3)
CONS 169.183.18.202 is raider1
CONS 169.183.18.201 is raider2
------------------------------
ok: BMC: Fileset IHS.BMC.perf.agent.is installed
ok: BMC: daemon listening on port 10128
ok: BMC: daemon bgssd in /etc/inetd.conf
ERROR: BMC: user perform does not have valid CONS () in /usr/adm/best1_default/local/setup/Collect.cfg
check BMC |awk '/^HOSTNAME/{if (line != "") print line; line =$NF ":"} /^HMC/{line=line $NF ":"} /BMC/ {line=line $1} END {print line}'
londew:cons2:cons1:ok:ok:ok:ERROR:
thanks again!