Start a Conversation

Unsolved

This post is more than 5 years old

3445

January 7th, 2016 04:00

Extract a block of text with sed/awk/grep from symdev list -v output?

For some offline discovery, I grab symdev list -v output. I want to extract a block of all information for a single device. I did quite a bit of searching and some of the following looked promising but I've not been able to translate them into a solution:
http://www.bing.com/search?q=exxtract+block+of+text+from+text+file++sed+aawk+grep&src=IE-SearchBox&FORM=IE8SRC

So for a device, say 00DA, I'd like to run a query against a saved symdev -sid XXX list -v output (saved in a symdev-list-v.txt file) that captures all information for just that one device and no other device that I can output to another file or use within a script. The relevant information is that all devices start with the following 3 lines (Device Physicaal Name, then a space, then Device Symmetrix Name):

 

Device Physical Name : Not Visible (or some assigned Physical name)

Device Symmetrix Name : 00DA

The end of a block can vary, so the best end point seems to be to find the next block, which will again be of the same format:

Device Physical Name : Not Visible (or some assigned Physical name)

Device Symmetrix Name : 00DB

Then finally to just lop off the last 2 lines off from the 00DB device to be left with all information from the 00DA device. Hopefully this is not too tricky and would greatly appreciate if a Unix/regex expert can help me out!?

Thanks,
Roy.

1.2K Posts

January 7th, 2016 07:00

Why not try using the -xml output and an XML parser?  Or, you could grab the XML output and just grep the fields you want?

1 Rookie

 • 

20.4K Posts

January 7th, 2016 18:00

cat symdev-v.out | grep -B 3 -w 00DA

Something like that ?

14 Posts

January 11th, 2016 15:00

XML parser would be great, but size constraints make it difficult (i.e. the "symdev list -v -output xml" from each array is 4-5x larger than the "symdev list -v") so as these run to multiple GB per XML output, the "symdev list -v" is the most manageable approach to collecting the info.

14 Posts

January 11th, 2016 16:00

Hi dynamox, I want to extract all information for the device, i.e. *everything* that is in the record for the device 00DA, i.e. exactly equivalent to running: symdev -sid XXXX show 00DA. Of course, symdev -sid XXXX list -v   contains every "show" record one after another. using grep -B 3 -w 00DA, will just get the line with 00DA, and the 3 lines before that.

Can you think of a way, that would extract (from a list -v), the entirety of the information for device 00DA ? (so everything in -B 3 -w 00DA, but also every line *after* 00DA right down to the start of the next device record)

1 Rookie

 • 

20.4K Posts

January 12th, 2016 12:00

play around with devices that have rdf pairing, i tested with clone and snaps ..seems to capture everything.

sed -n -e '/Device Symmetrix Name    : 00DA/,/Device Physical Name/ p' symdev-v.txt  |  sed -e '$d'

14 Posts

January 13th, 2016 07:00

This is great dynamox, thanks for this. I guess the only thing outstanding is how to also capture the "Device Physical Name     : Not Visible" and space above (and Device Physical Name might not be "Not Visible" and could have another value). i.e. to collect the entire record for the device?

i.e. Where you test for "/Device Symmetrix Name    : 00DA"

is there a way that you can think of to instead test for all of: "Device Physical Name     : Physical /Device Symmetrix Name    : 00DA"

so that the whole record is included?

1 Rookie

 • 

20.4K Posts

January 13th, 2016 21:00

my google kung fu is not leading me to what i want. You might need to start tinkering with perl, might be easier to parse.

14 Posts

January 15th, 2016 05:00

Thanks dynamo, my sed/perl is not good enough I guess (I don't even really see what the $d does in your note above though I see that it works!). I think your approach looks great though, so if either of these pages give an obvious clue on how to extract the multiline part that would be appreciated:

http://austinmatzko.com/2008/04/26/sed-multi-line-search-and-replace/

http://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string

http://stackoverflow.com/questions/1221245/sed-multiline-replace

http://askubuntu.com/questions/347223/sed-substitute-through-a-sentence-on-multiple-lines

These are more for replacing a multiline piece of text of course, but hopefully also applicable to picking out the region of text with multiline starting point of:

"Device Physical Name     : <some value> Physical /Device Symmetrix Name    : <symdev ID>"

12 Posts

June 14th, 2016 06:00

Please upload the output of symdev -sid xxxx list -v.

and let me know what kind of output u are looking for.

5 Posts

June 30th, 2016 14:00

There's probably a better way to do this...

#!/usr/bin/perl

$INFILE = '/path_to_symdev_output';

open(symdev,"<$INFILE") or die "Failed opening $INFILE ($!)";

$found = 0;

while ($line = ) {

   if ($found == 1) {

        last if ($line =~ /Device Symmetrix Name :/);

        print $line;

   if ($line =~ /Device Symmetrix Name : 00DA/) {

       $found = 1;

       print $line;

   }

}

No Events found!

Top