Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have below sample file(s).

Symmetrix logical device count=13
CLARiiON logical device count=0
Invista logical device count=0
Generic logical device count=0
==============================================================================
----- Host Bus Adapters ---------  ------ I/O Paths -----  ------ Stats ------
### HW Path                        Summary   Total   Dead  IO/Sec Q-IOs Errors
==============================================================================
   2 port2\path0                   degraded     13      3       -     0      3
   3 port3\path0                   degraded     13      3       -     0      3



Port Attributes for 10:00:00:00:c9:69:5b:70

Node WWN            : 20 00 00 00 c9 69 5b 70 
Port WWN            : 10 00 00 00 c9 69 5b 70 
Port Symname        : Emulex PPN-10:00:00:00:C9:69:5B:70
Port FCID           : 78004A
Port Type           : Fabric
Port State          : Operational
Port Service Type   : 8
Port Supported FC4  : 00 00 01 00 00 00 00 01 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
Port Active FC4     : 00 00 01 00 00 00 00 01 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
Port Supported Speed: 1 2 4 GBit/sec.
Port Speed          : 1 GBit/sec.
Max Frame Size      : 2048
OS Device Name      : \\.\Scsi2:
Num Discovered Ports: 2
Fabric Name         : 20 02 00 0d ec f1 00 c1 


Port Attributes for 10:00:00:00:c9:69:37:63

Node WWN            : 20 00 00 00 c9 69 37 63 
Port WWN            : 10 00 00 00 c9 69 37 63 
Port Symname        : Emulex PPN-10:00:00:00:C9:69:37:63
Port FCID           : 780098
Port Type           : Fabric
Port State          : Operational
Port Service Type   : 8
Port Supported FC4  : 00 00 01 00 00 00 00 01 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
Port Active FC4     : 00 00 01 00 00 00 00 01 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
                      00 00 00 00 00 00 00 00 
Port Supported Speed: 1 2 4 GBit/sec.
Port Speed          : 1 GBit/sec.
Max Frame Size      : 2048
OS Device Name      : \\.\Scsi3:
Num Discovered Ports: 2
Fabric Name         : 20 02 00 0d ec f0 b5 81 

I need to select only below part in powershell. How can i achieve this? It would be great to make object form this but splitting would be enough

==============================================================================
----- Host Bus Adapters ---------  ------ I/O Paths -----  ------ Stats ------
### HW Path                        Summary   Total   Dead  IO/Sec Q-IOs Errors
==============================================================================
   2 port2\path0                   degraded     13      3       -     0      3
   3 port3\path0                   degraded     13      3       -     0      3

Thanks a lot

PS.
I've tried to use below line of code but it returns not only needed block:

[regex]::match($file,'(={3,}).+(?=Port\sAttributes\sfor.+)',"singleline").value

PPS.
I'm really sorry, i'm not familiar enough with regexp, that's why i'm asking

share|improve this question

closed as off topic by Chopper3, Dan, Jenny D, Khaled, MadHatter Apr 2 '13 at 15:36

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
What have you tried so far? Where do you get the original block from? Is it always the same? –  Dan Apr 2 '13 at 10:30
    
Yes,sure I've tried this stuff: [regex]::match($file,'(={3,}).+(?=Port\sAttributes\sfor.+)',"singleline").value. But it returns the first "Port Attributes" block ac well. :( –  Eosfor Apr 2 '13 at 10:32
    
Is it always line numbers 5-10 that you need? Or is it possible there could be more HBAs listed after line 10? –  jscott Apr 2 '13 at 10:32
    
line numbers could be different unfortunately. but this block always starts with long line of "=" end next block always starts with "Port Attributes for" line –  Eosfor Apr 2 '13 at 10:35

1 Answer 1

up vote 3 down vote accepted

Assuming you've the provided log contents in a file hba.log, the following will return all lines starting with any of '=', '-', '#', or lines containing 1 or more white space characters, followed by a digit, followed by a white space character, followed by 'port':

Get-Content hba.log | Where-Object { $_ -match "^[=#-]|\s{1,}\d\sport" }

Tested here returns:

==============================================================================
----- Host Bus Adapters ---------  ------ I/O Paths -----  ------ Stats ------
### HW Path                        Summary   Total   Dead  IO/Sec Q-IOs Errors
==============================================================================
   2 port2\path0                   degraded     13      3       -     0      3
   3 port3\path0                   degraded     13      3       -     0      3

If the 2 port2\path0 lines start with a tab, or a specific number of spaces, we can re-write the above to use that instead. You'll need to clarify in your question what the possible values for lines 9-10[-n?] could contain if you need something more specific.

share|improve this answer
    
This works!! Thanks!! This example is so smart ). i'll take note of this for sure. Could you kindly give me a link or name of the book you read to do this stuff? I would like to read it too ) For all examples i have so far lines 9-10 starts with couple of space characters. At the moment i do not know what are other possible values. –  Eosfor Apr 2 '13 at 10:56
    
may i ask you to show me a way how to split this file to "Port Attributes" blocks? –  Eosfor Apr 2 '13 at 10:58
    
I'm not sure I could recommend a single book, but anything PCRE seems to be the most popular, or at least common, to learn. Try getting some reading in and then play with a regex tool such as Regexpal -- do a search for "regex tool online" or something. Could you explain what you mean by "Port Attributes" blocks? And how you intend to process or what you want to do with said "blocks"? You can either edit your question or start a new one if it's significantly different from your original question. –  jscott Apr 2 '13 at 11:56
    
actually the idea is to take this file and convert it into objects. Objects will be dynamic objects as they could contain dynamic number of "paths" and "Port Attribute" objects. I'll work on this further. Thanks for your help ) –  Eosfor Apr 2 '13 at 12:43
    
@Eosfor That seems a bit out-of-scope for this original question. Perhaps try to gather up a detailed summary of what you'd like to accomplish and post that as a new question. I'd be glad to help if I am able. –  jscott Apr 2 '13 at 14:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.