<?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: Korn Shell - reformat input file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133774#M316560</link>
    <description>TQ,&lt;BR /&gt;&lt;BR /&gt;It's refreshing to see clear description of input and output. Thanks!&lt;BR /&gt;There is a little discrepancy in that the name in the output seems to start in column 20, not 21 as indicated.&lt;BR /&gt;&lt;BR /&gt;Here is a perl solution, which you can stick in a korn shel script if you must:&lt;BR /&gt;&lt;BR /&gt;$ perl -ne 'printf ("%-10s%-10s%-30s%-13s%-4s0 0 2008\n","BEA46112",$1,$4,$3,$2) if /(\w+)\s+(\w+)\s+(\d+)\s+(\S.*)/' x&lt;BR /&gt;&lt;BR /&gt;The printf force the output to be left justified (the '-' in fixed length character fields '%&lt;N&gt;s' where &lt;N&gt; is the width. I even used this for the fixed text, to avoid typos &amp;amp; counting.&lt;BR /&gt;Ths print arguments come from a matching expression which looks for recognizable parts of the string \w+ for a word, \s+ for whitespace and so on.&lt;BR /&gt;&lt;BR /&gt;Enjoy!&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/N&gt;&lt;/N&gt;</description>
    <pubDate>Wed, 23 Jan 2008 02:23:30 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2008-01-23T02:23:30Z</dc:date>
    <item>
      <title>Korn Shell - reformat input file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133773#M316559</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Anybody please help me.&lt;BR /&gt;&lt;BR /&gt;I have input file as below :-&lt;BR /&gt;ADIL   LM      940328106109    MUHAMMAD ASYRAF B AZMAN&lt;BR /&gt;ADIL   LM      940923105071    MUHAMMAD DANIAL NASIRUDDIN&lt;BR /&gt;ADIL   LM      940818146028    MUHAMMAD FAIZAL B MOHD FAUZI&lt;BR /&gt;ADIL   PM      940607146234    NOR SYAKINA FARA BT MOHAMAD&lt;BR /&gt;ADIL   PM      940715105480    NORSHAFIKA BT SULAIMAN&lt;BR /&gt;ADIL   PM      14494   NUR AZIRA BT DARNALIS&lt;BR /&gt;ADIL   PM      940119145670    NUR AZIRA BT MOHD JANI&lt;BR /&gt;ADIL   PM      940729105596    NUR FARZANA BT MOHD KAMSAINY&lt;BR /&gt;&lt;BR /&gt;1st field = Class&lt;BR /&gt;2nd field = Code&lt;BR /&gt;1st &amp;amp; 2nd field length are (fix).&lt;BR /&gt;&lt;BR /&gt;3rd field = SocialNo (length not fix, 4 to 12 characters)&lt;BR /&gt;4rd field is a name (length not fix)&lt;BR /&gt;&lt;BR /&gt;My output file format as per attached.&lt;BR /&gt;1st field = "BEA46112" (fixed)&lt;BR /&gt;2nd field = Class &amp;amp; Must start at position 11.&lt;BR /&gt;3rd field = Name &amp;amp; Must start at position 21.&lt;BR /&gt;4rd field - SocialNo &amp;amp; Must Start at position 51.&lt;BR /&gt;5th field = Code &amp;amp; Must start at position 64.&lt;BR /&gt;6th fiels = "0 0 2008" (fixed) &amp;amp; Must start at position  68&lt;BR /&gt;of the output file.&lt;BR /&gt;&lt;BR /&gt;Kindly help how could I format the input file to get the formated output file as per attached through korn shell.&lt;BR /&gt;&lt;BR /&gt;TQ&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jan 2008 22:47:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133773#M316559</guid>
      <dc:creator>KAMARULZAMAN HJ ALI</dc:creator>
      <dc:date>2008-01-22T22:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Korn Shell - reformat input file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133774#M316560</link>
      <description>TQ,&lt;BR /&gt;&lt;BR /&gt;It's refreshing to see clear description of input and output. Thanks!&lt;BR /&gt;There is a little discrepancy in that the name in the output seems to start in column 20, not 21 as indicated.&lt;BR /&gt;&lt;BR /&gt;Here is a perl solution, which you can stick in a korn shel script if you must:&lt;BR /&gt;&lt;BR /&gt;$ perl -ne 'printf ("%-10s%-10s%-30s%-13s%-4s0 0 2008\n","BEA46112",$1,$4,$3,$2) if /(\w+)\s+(\w+)\s+(\d+)\s+(\S.*)/' x&lt;BR /&gt;&lt;BR /&gt;The printf force the output to be left justified (the '-' in fixed length character fields '%&lt;N&gt;s' where &lt;N&gt; is the width. I even used this for the fixed text, to avoid typos &amp;amp; counting.&lt;BR /&gt;Ths print arguments come from a matching expression which looks for recognizable parts of the string \w+ for a word, \s+ for whitespace and so on.&lt;BR /&gt;&lt;BR /&gt;Enjoy!&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/N&gt;&lt;/N&gt;</description>
      <pubDate>Wed, 23 Jan 2008 02:23:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133774#M316560</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-01-23T02:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Korn Shell - reformat input file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133775#M316561</link>
      <description>Thanks HEIN.&lt;BR /&gt;&lt;BR /&gt;Greats &amp;amp; it works.&lt;BR /&gt;&lt;BR /&gt;If I to mix the "BEA46112" with 1st Field ($1) without space in between and my output as follow :-&lt;BR /&gt;&lt;BR /&gt;BEA46112ADIL ...so on&lt;BR /&gt;&lt;BR /&gt;What the code I should change?&lt;BR /&gt;&lt;BR /&gt;The follow code : &lt;BR /&gt;perl -ne 'printf ("%-8s%-10s%-30s%-13s%-4s0 0 2008\n","BEA46112"$1,$4,$3,$2) if /(\w+)\s+(\w+)\s+(\d+)\s+(\S.*)/' x&lt;BR /&gt;&lt;BR /&gt;giving me error &lt;BR /&gt;Scalar found where operator expected at -e line 1, near ""BEA46112"$1"&lt;BR /&gt;        (Missing operator before $1?)&lt;BR /&gt;syntax error at -e line 1, near ""BEA46112"$1"&lt;BR /&gt;Execution of -e aborted due to compilation errors.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;-Kamarul</description>
      <pubDate>Wed, 23 Jan 2008 04:07:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133775#M316561</guid>
      <dc:creator>KAMARULZAMAN HJ ALI</dc:creator>
      <dc:date>2008-01-23T04:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Korn Shell - reformat input file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133776#M316562</link>
      <description>&amp;gt;&amp;gt; If I to mix the "BEA46112" with 1st Field ($1) without space in between and my output as follow : BEA46112ADIL ...so on&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; What the code I should change?&lt;BR /&gt;&lt;BR /&gt;That would be a minor change to the format.&lt;BR /&gt;Instead of fixed width 10 as originally requested, just use a %s for a 'tight' string.&lt;BR /&gt;&lt;BR /&gt;'printf ("%-8s...&lt;BR /&gt;'printf ("%s... &lt;BR /&gt;&lt;BR /&gt;Or, for a bigger change, hardcode the text in the format:&lt;BR /&gt;&lt;BR /&gt;$ perl -ne 'printf ("%-10s%-10s%-30s%-13s%-4s0 0 2008\n","BEA46112",$1,$4,$3,$2) if /(\w+)\s+(\w+)\s+(\d+)\s+(\S.*)/' x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;becomes&lt;BR /&gt;&lt;BR /&gt;perl -ne 'printf ("BEA46112%-10s%-30s%-13s%-4s0 0 2008\n",$1,$4,$3,$2) if /(\w+)\s+(\w+)\s+(\d+)\s+(\S.*)/' x&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jan 2008 05:21:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133776#M316562</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-01-23T05:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Korn Shell - reformat input file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133777#M316563</link>
      <description>&lt;!--!*#--&gt;You can take Hein's solution and turn it into awk:&lt;BR /&gt;awk '&lt;BR /&gt;{&lt;BR /&gt;name = $4   # collect variable field name&lt;BR /&gt;for (i = 5; i &amp;lt;= NF; ++i) name = name " " $i&lt;BR /&gt;printf "BEA46112%-10s%-30s%-13s%-4s0 0 2008\n", $1, name, $3, $2&lt;BR /&gt;} ' file</description>
      <pubDate>Wed, 23 Jan 2008 08:07:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/korn-shell-reformat-input-file/m-p/4133777#M316563</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-01-23T08:07:25Z</dc:date>
    </item>
  </channel>
</rss>

