<?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 Re: perl script reformat in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233103#M675465</link>
    <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; in the output "select volume 2", string "2" will refer to original input file field 2.&lt;BR /&gt;&lt;BR /&gt;You didn't make that very clear, originally.  Good specifications make for good code.&lt;BR /&gt;&lt;BR /&gt;Here's the revised version which tolerates fuzzier input.  Note that a valid line begins with "Volume" and can be found to contain  whitespace delimited "size" and "units" fields.&lt;BR /&gt;&lt;BR /&gt;# cat ./reformat&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    my ( $volno, $size, $units ) = m{^Volume\s(\d+)\s+.+?(\d+)\s*(.B)\s};&lt;BR /&gt;    next unless defined $size;&lt;BR /&gt;    if ( $size == 2000 &amp;amp;&amp;amp; $units eq 'GB' ) {&lt;BR /&gt;        print "select volume $volno\nassign letter=G\n"&lt;BR /&gt;    }&lt;BR /&gt;    elsif ( $size == 1000 &amp;amp;&amp;amp; $units eq 'GB' ) {&lt;BR /&gt;        print "select volume $volno\nassign letter=H\n"&lt;BR /&gt;    }&lt;BR /&gt;    elsif ( $size == 1020 &amp;amp;&amp;amp; $units eq 'MB' ) {&lt;BR /&gt;        print "select volume $volno\nassign letter=Q\n"&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Thu, 01 Apr 2010 14:51:41 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-04-01T14:51:41Z</dc:date>
    <item>
      <title>perl script reformat</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233100#M675462</link>
      <description>## start of input file&lt;BR /&gt;DISKPART&amp;gt;&lt;BR /&gt;  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info&lt;BR /&gt;  ----------  ---  -----------  -----  ----------  -------  ---------  --------&lt;BR /&gt;  Volume 0     G   Data File    NTFS   Partition   1000 GB  Healthy&lt;BR /&gt;  Volume 1     H   Quorum       NTFS   Partition   1020 MB  Healthy&lt;BR /&gt;  Volume 2                             Partition   2000 GB  Healthy&lt;BR /&gt;  Volume 3     C                NTFS   Partition    137 GB  Healthy    System&lt;BR /&gt;&lt;BR /&gt;DISKPART&amp;gt;&lt;BR /&gt;&lt;BR /&gt;## end of input file&lt;BR /&gt;&lt;BR /&gt;using perl, &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if "Size" column equals to 2000GB, then output&lt;BR /&gt;"select volume 2"&lt;BR /&gt;"assign letter=G"&lt;BR /&gt;if "size" column equals to 1000GB, then output &lt;BR /&gt;"select volume 0"&lt;BR /&gt;"assign letter=H"&lt;BR /&gt;if "size" column equals to 1020MB, then output &lt;BR /&gt;"select volume 1"&lt;BR /&gt;"assign letter=Q"&lt;BR /&gt;&lt;BR /&gt;Typically, when running the sciprt, should be able to read from input file, &lt;BR /&gt;reformat, then output like following; the input file content will dynamicly changes&lt;BR /&gt;&lt;BR /&gt;select volume 2&lt;BR /&gt;assign letter=G&lt;BR /&gt;select volume 0&lt;BR /&gt;assign letter=H&lt;BR /&gt;select volume 1&lt;BR /&gt;assign letter=G</description>
      <pubDate>Thu, 01 Apr 2010 13:31:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233100#M675462</guid>
      <dc:creator>Matthew_50</dc:creator>
      <dc:date>2010-04-01T13:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: perl script reformat</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233101#M675463</link>
      <description>&lt;!--!*#--&gt;Hi Matthew:&lt;BR /&gt;&lt;BR /&gt;You could do something like this:&lt;BR /&gt;&lt;BR /&gt;# cat ./reformat&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ( $size, $units );;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    next if $. &amp;lt; 3; #...skip two header lines...&lt;BR /&gt;&lt;BR /&gt;    ( $size, $units ) = m{\s(\d+)\s+(.B)\s};&lt;BR /&gt;&lt;BR /&gt;    if ( $size == 2000 and $units eq 'GB' ) {&lt;BR /&gt;        print "select volume 2\nassign letter=G\n"&lt;BR /&gt;    }&lt;BR /&gt;    elsif ( $size == 1000 and $units eq 'GB' ) {&lt;BR /&gt;        print "select volume 0\nassign letter=H\n"&lt;BR /&gt;    }&lt;BR /&gt;    elsif ( $size == 1020 and $units eq 'MB' ) {&lt;BR /&gt;        print "select volume 1\nassign letter=Q\n"&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...run as :&lt;BR /&gt;&lt;BR /&gt;# ./reformat file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 01 Apr 2010 14:02:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233101#M675463</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-04-01T14:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: perl script reformat</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233102#M675464</link>
      <description>Hello James, &lt;BR /&gt;&lt;BR /&gt;in the output "select volume 2", string "2" will refer to original input file field 2.&lt;BR /&gt;&lt;BR /&gt;for 2000GB volume, it will dedicate map to G&lt;BR /&gt;for 1000GB volume, it will dedicate map to H&lt;BR /&gt;for 1020MB volume, it will dedicate map to Q&lt;BR /&gt;&lt;BR /&gt;but input file, the first and the second field will change dynamically. &lt;BR /&gt;&lt;BR /&gt;Thank you.</description>
      <pubDate>Thu, 01 Apr 2010 14:19:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233102#M675464</guid>
      <dc:creator>Matthew_50</dc:creator>
      <dc:date>2010-04-01T14:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: perl script reformat</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233103#M675465</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; in the output "select volume 2", string "2" will refer to original input file field 2.&lt;BR /&gt;&lt;BR /&gt;You didn't make that very clear, originally.  Good specifications make for good code.&lt;BR /&gt;&lt;BR /&gt;Here's the revised version which tolerates fuzzier input.  Note that a valid line begins with "Volume" and can be found to contain  whitespace delimited "size" and "units" fields.&lt;BR /&gt;&lt;BR /&gt;# cat ./reformat&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    my ( $volno, $size, $units ) = m{^Volume\s(\d+)\s+.+?(\d+)\s*(.B)\s};&lt;BR /&gt;    next unless defined $size;&lt;BR /&gt;    if ( $size == 2000 &amp;amp;&amp;amp; $units eq 'GB' ) {&lt;BR /&gt;        print "select volume $volno\nassign letter=G\n"&lt;BR /&gt;    }&lt;BR /&gt;    elsif ( $size == 1000 &amp;amp;&amp;amp; $units eq 'GB' ) {&lt;BR /&gt;        print "select volume $volno\nassign letter=H\n"&lt;BR /&gt;    }&lt;BR /&gt;    elsif ( $size == 1020 &amp;amp;&amp;amp; $units eq 'MB' ) {&lt;BR /&gt;        print "select volume $volno\nassign letter=Q\n"&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 01 Apr 2010 14:51:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233103#M675465</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-04-01T14:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: perl script reformat</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233104#M675466</link>
      <description>If the data to parse (that table) is a list with fixed-width columns (you didn't tick "retain format", so we cannot see), the best way to pare the lines is using unpack.&lt;BR /&gt;&lt;BR /&gt;Volume ### Ltr Label Fs Type Size Status Info&lt;BR /&gt;&lt;BR /&gt;my %size = (&lt;BR /&gt;    kb =&amp;gt; 1024,&lt;BR /&gt;    mb =&amp;gt; 1024 * 1024,&lt;BR /&gt;    gb =&amp;gt; 1024 * 1024 * 1024,&lt;BR /&gt;    );&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    my ($vol, $xxx, $ltr, $lbl, $fs, $type, $size, $status, $info) = unpack "A11 A3 A11 A5 A10 A7 A9 A*", $_;&lt;BR /&gt;&lt;BR /&gt;    $size =~ s/^\s*(\d+)\s*([kKmMgG][bB])/$1*$size{lc$2}/e;&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Apr 2010 14:58:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233104#M675466</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2010-04-01T14:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: perl script reformat</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233105#M675467</link>
      <description>Thanks, James !!&lt;BR /&gt;&lt;BR /&gt;After some modify, it matches my requirement.</description>
      <pubDate>Thu, 01 Apr 2010 16:47:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-reformat/m-p/5233105#M675467</guid>
      <dc:creator>Matthew_50</dc:creator>
      <dc:date>2010-04-01T16:47:22Z</dc:date>
    </item>
  </channel>
</rss>

