noprompt
6 Indium

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

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.

Labels (2)
0 Kudos
8 Krypton

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

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?

0 Kudos
8 Krypton

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

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

Something like that ?

0 Kudos
noprompt
6 Indium

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

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.

0 Kudos
noprompt
6 Indium

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

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)

0 Kudos
8 Krypton

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

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'

noprompt
6 Indium

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

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     : <Not Visible, or possible value><NEWLINE>Physical /Device Symmetrix Name    : 00DA"

so that the whole record is included?

0 Kudos
8 Krypton

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

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.

0 Kudos
noprompt
6 Indium

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

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><NEWLINE>Physical /Device Symmetrix Name    : <symdev ID>"

0 Kudos
nikh8255
6 Indium

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

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

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

0 Kudos