1752732 Members
6257 Online
108789 Solutions
New Discussion юеВ

awk processing

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

awk processing

hello all,

I am having difficutly getting the following format:

vhost3,U9117.570.65C5B91-V4-C23,inndpr2ap1d1,inndpr2_ap1d1

vhost3,U9117.570.65C5B91-V4-C23,inndpr2ro1d1,inndpr2_ro1d1

I am trying to format all data from the following report:

--------------- -------------------------------------------- ------------------
vhost0 U9117.570.65C5B91-V4-C20 0x00000010

VTD wmbpr1ro1d1
Status Available
LUN 0x8100000000000000
Backing device wmbpr1_ro1d1
Physloc

SVSA Physloc Client Partition ID
--------------- -------------------------------------------- ------------------
vhost1 U9117.570.65C5B91-V4-C21 0x00000011

VTD wmbpr2ro1d1
Status Available
LUN 0x8100000000000000
Backing device wmbpr2_ro1d1
Physloc

SVSA Physloc Client Partition ID
--------------- -------------------------------------------- ------------------
vhost2 U9117.570.65C5B91-V4-C22 0x00000012

VTD inndpr1ap1d1
Status Available
LUN 0x8200000000000000
Backing device inndpr1_ap1d1
Physloc

VTD inndpr1ro1d1
Status Available
LUN 0x8100000000000000
Backing device inndpr1_ro1d1
Physloc

SVSA Physloc Client Partition ID
--------------- -------------------------------------------- ------------------
vhost3 U9117.570.65C5B91-V4-C23 0x00000013

VTD inndpr2ap1d1
Status Available
LUN 0x8200000000000000
Backing device inndpr2_ap1d1
Physloc

VTD inndpr2ro1d1
Status Available
LUN 0x8100000000000000
Backing device inndpr2_ro1d1
Physloc

can someone please help?

Thanks

Chris.
hello
4 REPLIES 4
Hein van den Heuvel
Honored Contributor
Solution

Re: awk processing

Hello Chris,

The general solution for such problems is to become a 'gatherer'.
Look for stuff (string patterns!) you can recognize and think are stable, and grab bits and pieces only you see somethign which suggests all pieces should have been accumulated.
After printing often you then need to reset the pieces for the next round, but here you want to keep a header piece which does nto come back each time.

The is a sample awk solution. Just a little more than a 1-liner:

------------------------- test.awk --------
BEGIN { OFS = "," }
/^---/ { getline; host=$1; name=$2 }
/^VTD/ { vtd = $2 }
/^Back/{ print host,name,vtd,$3}
-------------------------------------------

use as: # awk -f test.awk test.txt

Notice:
1) The BEGIN clause sets the Output Field Seperator (OFS) as comma for convenience

2) That "vhostX" is probably not stable enough to latch on to. So the script latches on the the recognizable seperators in the begin of the line before, reads a line (getline) and uses the data from teh next line, not the latch line.

Enjoy!
Hein.


lawrenzo_1
Super Advisor

Re: awk processing

Hi Hein,

ok thanks - I'll have a look at what I can come up with.

Chris.
hello
lawrenzo_1
Super Advisor

Re: awk processing

Thanks again Hein,

I have adapted the code for other information I also require.

Chris.
hello
Hein van den Heuvel
Honored Contributor

Re: awk processing

I meant to carry the hunter/gatherer metaphor further. Hunt for match candidates, gather droppings,... :-)

>> I'll have a look at what I can come up with

It should already work.
If it does not, then that's probably because the forum ate spaces.
I like using 'anchors' in my search strings, whether they are strictly needed or not, to prevent stray matches and to speed up misses. Here I used "^" to anchor to the begin of line... but that only works as written when there are no leading spaces.

If you have trouble with the solution, then be sure the reply with the EXACT input example in a TXT file, and perhaps a couple exact outputs as desirable.

Cheers,
Hein.