1752634 Members
6040 Online
108788 Solutions
New Discussion юеВ

Re: awk help ?

 
SOLVED
Go to solution
Stuart Abramson
Trusted Contributor

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...

8 REPLIES 8
Sandman!
Honored Contributor
Solution

Re: awk help ?

How about giving sed a try?

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

cheers!
James R. Ferguson
Acclaimed Contributor

Re: awk help ?

Hi Stuart:

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

Regards!

...JRF...
Jason Cannon
Advisor

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;
Victor Fridyev
Honored Contributor

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
Rodney Hills
Honored Contributor

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...
Tim D Fulford
Honored Contributor

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
-
Stuart Abramson
Trusted Contributor

Re: awk help ?

Thanks all!
Howard Marshall
Regular Advisor

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