3

I am trying to process a text file that contains multiple entries, I am interested in the Data filed of the text which consists of Name, Id, Size and Page83 ID.

Command: show PhysicalDisk name='IBM (721)'
Status: Success
Time: 2017-06-30 15:50:50,051 EST
Data:
  Name = IBM (721)
  Id = 0004fb0000180000d27ba1c974a69157
  Size (GiB) = 15.0
  Shareable = No
  Page83 ID = 360050768018385ace800000000000d6a
  Thin Provision = Yes
  VolumeGroup = Generic_SAN_Volume_Group @ Unmanaged FibreChannel Storage Array  [FibreChannel Volume Group]
  San Server = Unmanaged FibreChannel Storage Array  [Unmanaged FibreChannel Storage Array]
Command: show PhysicalDisk name='IBM (722)'
Status: Success
Time: 2017-06-30 15:50:53,636 EST
Data:
  Name = IBM (730)
  Id = 0004fb0000180000627770ff185759b6
  Size (GiB) = 100.0
  Shareable = No
  Page83 ID = 360050768018385ace800000000000d6b
  Thin Provision = Yes
  VolumeGroup = Generic_SAN_Volume_Group @ Unmanaged FibreChannel Storage Array  [FibreChannel Volume Group]
  San Server = Unmanaged FibreChannel Storage Array  [Unmanaged FibreChannel Storage Array]

I would like to process this text and put it in the excel sheet rows and columns.

enter image description here

This is just a sample output for two data fields. Also want to know how can we have this in place for "N number" of data fields.

  • If you want to create the excel sheet, I recommend using python with excel library. Or do you want to generate an csv file to be imported by excel? Then the country settings of excel are importent (field delimiter differ!). Or you can finally generate a tab-separated output to copy&paste into excel. WHat do you want? – Philippos Jun 30 '17 at 6:39
  • For a simple comma-separated csv you could use something like sed -n '/Name = /!d;N;N;N;N;y/\n/,/;s/, *Shareable = [^,]*//;s/[^,=]*= //g;p' yourfile – Philippos Jun 30 '17 at 6:51
  • @Phillops Thank you for the reply. Yes, I want to generate a csv file to be imported by Excel sheet. – IgniteLX Jun 30 '17 at 7:10
  • PhillopsThanks a ton it worked like a charm! – IgniteLX Jun 30 '17 at 7:13
  • So I'll add explanation to it in an answer – Philippos Jun 30 '17 at 7:14
2

For a simple comma-separated csv to be imported into excel you could use something like

sed -n '/Name = /!d
  N;N;N;N
  y/\n/,/
  s/, *Shareable = [^,]*//
  s/[^,=]*= //g;p' yourfile

The first line deletes all lines except the Name = ones. Continue only for those and append the four next lines to the buffer with N. The y command replaces the newlines between the lines with the separating commas. The first s command removes the Shareable line and the second one removes the part upto the = to leave only the value. It will work for any number of rows. Text fields will be identified automatically without quotes in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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