<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to extract ID and device file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068079#M94692</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt; Have a file contains Device ID and device names and would like to extract only ID and corresponding device name to it from the file.&lt;BR /&gt;&lt;BR /&gt;One of the entry for one Device in the file shows as:&lt;BR /&gt;&lt;BR /&gt;CLARiiON ID=APM00054902225 [hostname]&lt;BR /&gt;Logical device ID=60060160F0C41600DDA5BE5057F3DB11 [ERM_1407]&lt;BR /&gt;state=alive; policy=CLAROpt; priority=0; queued-IOs=0&lt;BR /&gt;Owner: default=SP B, current=SP B&lt;BR /&gt;==============================================================================&lt;BR /&gt;---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---&lt;BR /&gt;### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors&lt;BR /&gt;==============================================================================&lt;BR /&gt; 16 0/2/1/0.2.16.0.0.4.2      c16t4d2    SP A1     active  alive      0      1&lt;BR /&gt; 17 0/6/1/0.1.16.0.0.4.2      c17t4d2    SP A0     active  alive      0      1&lt;BR /&gt; 18 0/2/1/0.1.16.0.0.4.2      c18t4d2    SP B0     active  alive      0      1&lt;BR /&gt; 19 0/6/1/0.2.16.0.0.4.2      c19t4d2    SP B1     active  alive      0      1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Looking for outcome as:&lt;BR /&gt;&lt;BR /&gt;ERM_1047 c16t4d2&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance.</description>
    <pubDate>Mon, 10 Sep 2007 13:09:19 GMT</pubDate>
    <dc:creator>IT_2007</dc:creator>
    <dc:date>2007-09-10T13:09:19Z</dc:date>
    <item>
      <title>How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068079#M94692</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt; Have a file contains Device ID and device names and would like to extract only ID and corresponding device name to it from the file.&lt;BR /&gt;&lt;BR /&gt;One of the entry for one Device in the file shows as:&lt;BR /&gt;&lt;BR /&gt;CLARiiON ID=APM00054902225 [hostname]&lt;BR /&gt;Logical device ID=60060160F0C41600DDA5BE5057F3DB11 [ERM_1407]&lt;BR /&gt;state=alive; policy=CLAROpt; priority=0; queued-IOs=0&lt;BR /&gt;Owner: default=SP B, current=SP B&lt;BR /&gt;==============================================================================&lt;BR /&gt;---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---&lt;BR /&gt;### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors&lt;BR /&gt;==============================================================================&lt;BR /&gt; 16 0/2/1/0.2.16.0.0.4.2      c16t4d2    SP A1     active  alive      0      1&lt;BR /&gt; 17 0/6/1/0.1.16.0.0.4.2      c17t4d2    SP A0     active  alive      0      1&lt;BR /&gt; 18 0/2/1/0.1.16.0.0.4.2      c18t4d2    SP B0     active  alive      0      1&lt;BR /&gt; 19 0/6/1/0.2.16.0.0.4.2      c19t4d2    SP B1     active  alive      0      1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Looking for outcome as:&lt;BR /&gt;&lt;BR /&gt;ERM_1047 c16t4d2&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance.</description>
      <pubDate>Mon, 10 Sep 2007 13:09:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068079#M94692</guid>
      <dc:creator>IT_2007</dc:creator>
      <dc:date>2007-09-10T13:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068080#M94693</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;I think,&lt;BR /&gt;&lt;BR /&gt;ioscan -H &lt;PATH&gt; will do it. &lt;BR /&gt;&lt;BR /&gt;You may need some more processing to get exactly what you want, but you can use awk.&lt;BR /&gt;&lt;BR /&gt;SEP&lt;/PATH&gt;</description>
      <pubDate>Mon, 10 Sep 2007 13:13:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068080#M94693</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2007-09-10T13:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068081#M94694</link>
      <description>execute powermt display dev=&lt;LUN&gt; for each LUN and pipe the output to,&lt;BR /&gt;&lt;BR /&gt;egrep "Logical|active alive" |head -2| awk '{if ($1=="Logical") printf $4" ";else print $3}'&lt;/LUN&gt;</description>
      <pubDate>Mon, 10 Sep 2007 13:23:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068081#M94694</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2007-09-10T13:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068082#M94695</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# perl -nle '$id=$1 if m{\[(ERM.+)\]};print join " ",$id,$1 if m{(c\d+t\d+d\d+)}' file&lt;BR /&gt; &lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 10 Sep 2007 13:37:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068082#M94695</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-10T13:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068083#M94696</link>
      <description>awk '/device/{x=z[split(y[split($NF,y,"[")],z,"]")-1]};/active alive/{print x,$3;exit}' file</description>
      <pubDate>Mon, 10 Sep 2007 14:04:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068083#M94696</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-09-10T14:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068084#M94697</link>
      <description>May be I am doing wrong...&lt;BR /&gt;&lt;BR /&gt; I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2.&lt;BR /&gt;&lt;BR /&gt;Tried all above suggestions and didn't work.&lt;BR /&gt;&lt;BR /&gt;Would you please check and help me.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Mon, 10 Sep 2007 14:47:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068084#M94697</guid>
      <dc:creator>IT_2007</dc:creator>
      <dc:date>2007-09-10T14:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068085#M94698</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2.&lt;BR /&gt;&lt;BR /&gt;Why would you expect only that result from the data you provided?&lt;BR /&gt;&lt;BR /&gt;Using my Perl script:&lt;BR /&gt;&lt;BR /&gt;# perl -nle '$id=$1 if m{\[(ERM.+)\]};print join " ",$id,$1 if m{(c\d+t\d+d\d+)}' file&lt;BR /&gt;&lt;BR /&gt;...and your posted "file", returned:&lt;BR /&gt;&lt;BR /&gt;ERM_1407 c16t4d2&lt;BR /&gt;ERM_1407 c17t4d2&lt;BR /&gt;ERM_1407 c18t4d2&lt;BR /&gt;ERM_1407 c19t4d2&lt;BR /&gt;&lt;BR /&gt;...That is, I am matching "ERM" in square brackets and reporting that current value togehter with items that match a disk device file format (cXtYdZ).  What are we missing?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 10 Sep 2007 14:56:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068085#M94698</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-10T14:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068086#M94699</link>
      <description>&amp;gt;&amp;gt; May be I am doing wrong... &lt;BR /&gt;&amp;gt;&amp;gt; I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2. &lt;BR /&gt;&lt;BR /&gt;Well, the problem could be that your input specification wats not clear enough.&lt;BR /&gt;&lt;BR /&gt;And now that the suggestions did not work, you failed to indicate what, according to you, was wrong with examples.&lt;BR /&gt;&lt;BR /&gt;Ayway,&lt;BR /&gt;&lt;BR /&gt;I'm thinking you have many entries and [ERM_XXXX] and each several ctd value, but you just want the first matching, for one.&lt;BR /&gt;&lt;BR /&gt;If that is correct, then the folling perl script will do the job:&lt;BR /&gt;&lt;BR /&gt;------------ device.pl --------&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $seen;&lt;BR /&gt;my $device = shift or die "Please provide device name to look for, and input file like 'ERM_1407 device.txt'";&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  if (/^Logical/) {&lt;BR /&gt;    $seen = /\[$device\]/ ?  1 : 0&lt;BR /&gt;  }&lt;BR /&gt;  if ($seen &amp;amp;&amp;amp; /\s(c\d+t\d+d\d+)/) {&lt;BR /&gt;     print "$device $1\n";&lt;BR /&gt;     $seen = 0;&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;-----------------&lt;BR /&gt;&lt;BR /&gt;Usage sample:&lt;BR /&gt;&lt;BR /&gt;$ perl device.pl ERM_1407 device.txt&lt;BR /&gt;&lt;BR /&gt;Note, the match for the device name as codes is exact. &lt;BR /&gt;You can loosen that up a lot by replacing&lt;BR /&gt;/\[$device\]/ &lt;BR /&gt;with just: &lt;BR /&gt;/$device/&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Sep 2007 16:28:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068086#M94699</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-09-10T16:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068087#M94700</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;  It is also giving alternate devices for the same LUN but I am looking for one device path for each LUN.&lt;BR /&gt;&lt;BR /&gt;ERM_1405 c16t4d0&lt;BR /&gt;ERM_1405 c17t4d0&lt;BR /&gt;ERM_1405 c18t4d0&lt;BR /&gt;ERM_1405 c19t4d0&lt;BR /&gt;ERM_1407 c16t4d2&lt;BR /&gt;ERM_1407 c17t4d2&lt;BR /&gt;ERM_1407 c18t4d2&lt;BR /&gt;ERM_1407 c19t4d2&lt;BR /&gt;ERM_1401 c16t3d5&lt;BR /&gt;ERM_1401 c17t3d5&lt;BR /&gt;ERM_1401 c18t3d5&lt;BR /&gt;ERM_1401 c19t3d5&lt;BR /&gt;ERM_1403 c16t3d6&lt;BR /&gt;ERM_1403 c17t3d6&lt;BR /&gt;ERM_1403 c18t3d6&lt;BR /&gt;ERM_1403 c19t3d6&lt;BR /&gt;&lt;BR /&gt;  How do I avoid to get multiple paths for same LUN. One more thing: not all LUN names starts with ERM, some of them starts with gc_ and some of them starts with something. So how do I get all these LUNs ?&lt;BR /&gt;&lt;BR /&gt;Thank you for quick response.</description>
      <pubDate>Mon, 10 Sep 2007 16:38:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068087#M94700</guid>
      <dc:creator>IT_2007</dc:creator>
      <dc:date>2007-09-10T16:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068088#M94701</link>
      <description>Hi (again)"&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2. &lt;BR /&gt;&lt;BR /&gt;OK, this comes closer to meeting that goal as stated:&lt;BR /&gt;&lt;BR /&gt;# perl -nle 'BEGIN{$pat=shift};$id=$1 if m{\[($pat)\]};print join " ",$id,$1 if $id &amp;amp;&amp;amp;  m?(\bc\d+t\d+d\d+\b)?' ERM_1407 file&lt;BR /&gt;&lt;BR /&gt;...yields:&lt;BR /&gt;&lt;BR /&gt;ERM_1407 c16t4d2&lt;BR /&gt;&lt;BR /&gt;...or nothing if there is no matching "ERM_1407" in square brackets.  Pass the argument you want to match followed by the file just like you would write a 'grep' argument and file.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 10 Sep 2007 17:10:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068088#M94701</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-10T17:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068089#M94702</link>
      <description>Did you try the awk construct I have posted? It does exactly what you're looking for viz., print the device ID followed by the device filename on the same line and it excludes the alternates.</description>
      <pubDate>Mon, 10 Sep 2007 17:12:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068089#M94702</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-09-10T17:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068090#M94703</link>
      <description>Ah, you do want all and not just 'grep' for one. Try:&lt;BR /&gt;&lt;BR /&gt;$ perl -nle '$dev=$1 if /^Logi.*\[(.*)\]/; if ($dev &amp;amp;&amp;amp; /\s(c\d+t\S+)\s/) { print "$dev $1";$dev=""}&lt;BR /&gt;' devices.txt&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$dev=$1 if /^Logi.*\[(.*)\]/; # remember stuff between box if line starts with 'Logi'&lt;BR /&gt;if ($dev &amp;amp;&amp;amp; /\s(c\d+t\S+)\s/) # If we have a device and it looks like a 'ctd' on line&lt;BR /&gt;{ print "$dev $1";$dev=""} # print and clear device.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Sep 2007 17:30:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068090#M94703</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-09-10T17:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068091#M94704</link>
      <description>sandman,&lt;BR /&gt;&lt;BR /&gt; Tried your method by simply copy and paste but didn't return anything.&lt;BR /&gt;&lt;BR /&gt;awk '/device/{x=z[split(y[split($NF,y,"[")],z,"]")-1]};/active alive/{print x,$3;exit}' file1.out</description>
      <pubDate>Tue, 11 Sep 2007 09:51:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068091#M94704</guid>
      <dc:creator>IT_2007</dc:creator>
      <dc:date>2007-09-11T09:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ID and device file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068092#M94705</link>
      <description>Thanks a bunch to James for simple solution - one liner!!!</description>
      <pubDate>Tue, 11 Sep 2007 10:05:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-extract-id-and-device-file/m-p/5068092#M94705</guid>
      <dc:creator>IT_2007</dc:creator>
      <dc:date>2007-09-11T10:05:47Z</dc:date>
    </item>
  </channel>
</rss>

