perl514 has asked for the wisdom of the Perl Monks concerning the following question:
Respected Monks,
Given below is an extract from a file that I wish to extract certain portions from.
7 hostname12 Generic-legacy 10000000AB210ACF6 --- 10000000AB210ACF4 2:5:4 10000000AB210ACF4 2:3:4 10000000AB210ACF6 3:5:4 9 hostname13 Generic 10000000AB2A3006A 3:5:2 10000000AB2A30068 2:5:2 20 hostname14 Generic-legacy 10000000AB2A3000C --- 10000000AB2A3000E 3:3:1 21 HOSTNAME Generic 22 hsname12 Generic-legacy 10000000ABCDE004A 3:3:3 10000000ABCDE004A 3:5:2 10000000ABCDE0048 2:3:3 23 srvernam Generic-legacy 5001438002A3004A 3:3:3 5001438002A3004A --- 5001438002A30048 2:3:3 5001438002A30048 2:5:2 5001438002A30048 2:5:2
This is the 3par showhost command output. It basically shows the Host ID, the name of the host, the host setting, the HBA WWN and the 3par Storage Array port.
I just need to extract the portion, if there is a "---" or a blank line in there...such as
7 hostname12 Generic-legacy 10000000AB210ACF6 --- 10000000AB210ACF4 2:5:4 10000000AB210ACF4 2:3:4 10000000AB210ACF6 3:5:4
or
23 srvernam Generic-legacy 5001438002A3004A 3:3:3 5001438002A3004A --- 5001438002A30048 2:3:3 5001438002A30048 2:5:2 5001438002A30048 2:5:2
or
21 HOSTNAME Generic
So basically the way I want is, the output should leave out if all the entries have a d:d:d at the end like so
9 hostname13 Generic 10000000AB2A3006A 3:5:2 10000000AB2A30068 2:5:2
So I tried a lot of stuff, and none of it worked. So I thought "Why not take everything that starts with a digit upto the part that just ends before the next digit and see if a "---" or a blank space is there.
Here is my script. I tried a lot of stuff, tried setting the $/ to "" and then to undef and then to \n\n, but it doesn't seem to work. So I removed the $/ from my script and started over (once again). As of now, my brain is completely a tangled mess, so please do not get pissed with the script below.
#!/usr/bin/perl use warnings; use strict; while (<>) { chomp; next if /Id Name Persona -WWN\/iSCSI_Name- Port/; if(/(?<loggedout>[d]+.*?\p{Hex}{16}.*?(--- |\s+))/sm) { print "$+{loggedout}\n"; } }
The script above does not output anything. I can easlity pull out just the line with the "---". Thats not a problem. What I want is, the whole host block associated with it. Any pointers would help. I am not looking for pre written code, I really badly need to crack this on my own, but I have miserably misunderstood the regex...please help me untangle my brain :).
Perlpetually Indebted To PerlMonks
http://dwimperl.com/windows.html is a boon for Windows.use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
|
---|