Get a string from lines of output

get Disk Name from bellow text

hi,
as an example , I have bellow text in a file, please look at under
Logical Drive: 13 , i made Status = Failed

So if its see Status=Failed, it will give the Disk name .( i was
thinking, if Status is failed then read next 4 lines , and get the
output from last line )

     Status: Failed   ----------- if status failed
     Array Accelerator: Enabled
     Unique Identifier: 600508B1001CFA9558F7E279175867E9
     Disk Name: /dev/cciss/c0d12   --------------------

Bellow the output from of the text file

  Logical Drive: 12
     Size: 1.8 TB
     Fault Tolerance: RAID 0
     Heads: 255
     Sectors Per Track: 32
     Cylinders: 65535
     Stripe Size: 256 KB
     Status: OK
     Array Accelerator: Enabled
     Unique Identifier: 600508B1001C697EB6CA50E02EFC3E4D
     Disk Name: /dev/cciss/c0d11
     Mount Points:
     Logical Drive Label: A0CD40E5PACCRID11411PT4FE83

  physicaldrive 1I:1:13
     Port: 1I
     Box: 1
     Bay: 13
     Status: OK
     Drive Type: Data Drive
     Interface Type: SATA
     Size: 2000.3 GB
     Firmware Revision: HPG2
     Serial Number: WMAY03818756
     Model: ATA     MB2000EAZNL
     SATA NCQ Capable: True
     SATA NCQ Enabled: True
     PHY Count: 1
     PHY Transfer Rate: 3.0GBPS

Array: M
Interface Type: SATA
Unused Space: 0 MB
Status: OK

  Logical Drive: 13
     Size: 1.8 TB
     Fault Tolerance: RAID 0
     Heads: 255
     Sectors Per Track: 32
     Cylinders: 65535
     Stripe Size: 256 KB
     Status: Failed
     Array Accelerator: Enabled
     Unique Identifier: 600508B1001CFA9558F7E279175867E9
     Disk Name: /dev/cciss/c0d12
     Mount Points: None
     Logical Drive Label: A0CD40E8PACCRID11411PT4A31D

  physicaldrive 1I:1:14
     Port: 1I
     Box: 1
     Bay: 14
     Status: OK
     Drive Type: Data Drive
     Interface Type: SATA
     Size: 2000.3 GB
     Firmware Revision: HPG2
     Serial Number: WMAY03697431
     Model: ATA     MB2000EAZNL
     SATA NCQ Capable: True
     SATA NCQ Enabled: True
     PHY Count: 1
     PHY Transfer Rate: 3.0GBPS

Can any one please help me with the logic

On 09/05/2012 04:49 PM, Ferdous ara wrote:

get Disk Name from bellow text

hi,
as an example , I have bellow text in a file, please look at under
Logical Drive: 13 , i made Status = Failed

So if its see Status=Failed, it will give the Disk name .( i was
thinking, if Status is failed then read next 4 lines , and get the
output from last line )

Have you tried implementing that? Did it work? If not, what happened?

If you know that the disk name will always follow (ie. appear below) the
status, try using a flip flop:

File.foreach(“status.txt”) do |line|
if line[/Status: Failed/] … line[/Status: OK/]
puts line if line[/Disk Name:/]
end
end

If you know that the disk name will always follow (ie. appear below) the
status, try using a flip flop:

File.foreach(“status.txt”) do |line|
if line[/Status: Failed/] … line[/Status: OK/]
puts line if line[/Disk Name:/]
end
end

Thats great thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs