Re: awk help ? (324 Views)
Reply
Trusted Contributor
Stuart Abramson
Posts: 278
Registered: ‎07-15-1999
Message 1 of 9 (324 Views)
Accepted Solution

awk help ?

I want to extract the following sequence:

---------------------------------------------------
Local Remote
-------------------------- -----------------------
Symmetrix ID RA STD R1/B Symmetrix ID R2 BCV
------------ -- ---- ---- ------------ ---- ----
000185700973 1 1E8 52B 000185702367 9A2 436
1F0 533 9AA 50D
1F8 53B 9B2 515
2FF 57B 0DD 532
303 57F 0E1 536
---------------------------------------------------

from the following command output:

# symreplicate -g fsproddg show

Group name: fsproddg
Host name: ohibks05

Device lists:
{
---------------------------------------------------
Local Remote
-------------------------- -----------------------
Symmetrix ID RA STD R1/B Symmetrix ID R2 BCV
------------ -- ---- ---- ------------ ---- ----
000185700973 1 1E8 52B 000185702367 9A2 436
1F0 533 9AA 50D
1F8 53B 9B2 515
2FF 57B 0DD 532
303 57F 0E1 536
---------------------------------------------------
}

Command line arguments:
{
Group type : Device Group

Scripts:
{
preaction : Not specified
postaction : Not specified
postcycle : /usr/emc/scripts/postcycle.sh
steperror : /usr/emc/scripts/error.sh
}

-consistent : True
-rdb : Not specified
-vxfs : Not specified
-ppath : Not specified
}

Options file settings:
{
Replicate hop type : Single hop

Maximum cycles : 1
Cycle overflow method : Next
Cycle delay (hh:mm) : 00:30

Use final BCV : True
Log Step : False

Protection : 0 - CLI_C_REPLICATE_PROTECT_DEFAULT

Timers:
{
---------------------------------------------------------
Type Time Limit Sleep Time Max Sleep Calc. Max
(hh:mm:ss) (hh:mm:ss) Time Factor Sleep Time
---- ---------- ---------- ----------- ----------
GEN 00:30:00 00:00:10 1 00:00:10
RDF 04:00:00 00:00:15 4 00:01:00
BCV 02:00:00 00:00:10 3 00:00:30
---------------------------------------------------------
}
}


I tried the following:

# symreplicate -g fsproddg show | awk '/\{/, /\}/ {print $0}'

But I got too much output. You'll note that there are several sequences delimited with { }. I only want the first...

Honored Contributor
Sandman!
Posts: 2,220
Registered: ‎01-13-2005
Message 2 of 9 (324 Views)

Re: awk help ?

How about giving sed a try?

# symreplicate -g fsproddg show | sed '/}/q'

cheers!
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 9 (324 Views)

Re: awk help ?

Hi Stuart:

# awk '{if ($0~/\{/) {print;while ($0!~/\}/) {getline;print};exit}}' filename

Regards!

...JRF...
Advisor
Jason Cannon
Posts: 20
Registered: ‎09-20-2001
Message 4 of 9 (324 Views)

Re: awk help ?

Here'a a way to do it in perl.

#!/usr/bin/perl

open (CMD,"symreplicate -g fsproddg show"|) or die;
while () {
last if (/}/);
print if $found_first_stanza;
if (/{/) {
$found_first_stanza=1;
}
}
close (CMD);
exit;
Honored Contributor
Victor Fridyev
Posts: 937
Registered: ‎07-01-1998
Message 5 of 9 (324 Views)

Re: awk help ?

Hi,

Try something like this :

awk 'BEGIN {f=0}
/\{/ {f=1; next}
/\}/ {exit}
{if(f==1)print}'

HTH
Entities are not to be multiplied beyond necessity - RTFM
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 6 of 9 (324 Views)

Re: awk help ?

pipe the output to-
sed -e '1,/^{/d' -e '/^}/,$d'

This deletes from the first line to the first {, then deletes from a } to the end.

HTH

-- Rod Hills
There be dragons...
Honored Contributor
Tim D Fulford
Posts: 1,424
Registered: ‎12-11-2000
Message 7 of 9 (324 Views)

Re: awk help ?

# symreplicate -g fsproddg show | perl -ane 'INIT{$f=0};if(m/{/){$f++};if($f==1){print "@F\n"}; if(m/}/){$f++}'

# symreplicate -g fsproddg show | awk 'BEGIN{f=0};/\{/{f=f+1};{if (f==1) {print $0}}; /\}/{f=f+1}'

take your pick... they are structurally the same...

Tim
-
Trusted Contributor
Stuart Abramson
Posts: 278
Registered: ‎07-15-1999
Message 8 of 9 (324 Views)

Re: awk help ?

Thanks all!
Regular Advisor
Howard Marshall
Posts: 86
Registered: ‎09-26-2005
Message 9 of 9 (324 Views)

Re: awk help ?

Those are all great pieces of advice that will work well but I personally think the simplest way to do it would be to add one line to your desired output and use

Device lists:

As your start string and

}


as your stop string on your awk search. Then, if you really must have only the stuff between the brackets grep out the Device lists: line and there you are.

Howard
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.