<?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: Formating output to fixed lenght in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721529#M948081</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;While I would probably do this in perl of awk (it would be much faster), you can do it within the shell:&lt;BR /&gt;&lt;BR /&gt;Your:&lt;BR /&gt;DAT=`printf "%.378s\n" $LIN` &lt;BR /&gt;echo $DAT &amp;gt;&amp;gt; test &lt;BR /&gt;&lt;BR /&gt;becomes:&lt;BR /&gt;&lt;BR /&gt;DAT=$(printf '%-378.378s' "${LIN}")&lt;BR /&gt;echo "${DAT}" &amp;gt;&amp;gt; test&lt;BR /&gt;&lt;BR /&gt;Note that echo does an implicit linefeed so that no LF is needed in the printf. The quotes around ${DAT} are required to include the white space. I have also replaced your backticks with the more modern syntax $(command)&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 10 May 2002 15:19:46 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2002-05-10T15:19:46Z</dc:date>
    <item>
      <title>Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721527#M948079</link>
      <description>Hello Great Ones:&lt;BR /&gt;I???m trying for the last few days to get a formatted output on a file.&lt;BR /&gt;I have 100???s of windows *82.txt files with this format:&lt;BR /&gt;&lt;BR /&gt;"header*GSIFDS*OO*T"&lt;BR /&gt;"H","15650010","1","5/8/2002","5/13/2002","somemore123","B24","B0"&lt;BR /&gt;"I","050526","5","16.54","NONE"&lt;BR /&gt;"I","050535","6","26.8","NONE"&lt;BR /&gt;"I","000936","7","29.92","NONE"&lt;BR /&gt;"I","014160","8","47","NONE"&lt;BR /&gt;"I","KI21340","9","17.18","NONE"&lt;BR /&gt;"I","04460","10","38.7","NONE"&lt;BR /&gt;"C","NONE"&lt;BR /&gt;"C","NONE"&lt;BR /&gt;"C","NONE"&lt;BR /&gt;"trailer*GSIFDS*OO*B24*12"&lt;BR /&gt;&lt;BR /&gt;These are comma separated fields on a database, the DBM reads these lines sequentially (quotes and all) and imports them into its own proprietary format.&lt;BR /&gt;My task in the UX world is to strip all \r and \n to make it a one liner file ??? which I was able to do with:&lt;BR /&gt;tr -d "[\015\012]" &amp;lt; test &amp;gt; testout&lt;BR /&gt;&lt;BR /&gt;My problem is to format each line with a total length of 378 bytes disregarding the length of actual data characters.&lt;BR /&gt;My latest script looks like:&lt;BR /&gt;&lt;BR /&gt;rm -f test&lt;BR /&gt;cat *82.txt | while read LIN&lt;BR /&gt;do&lt;BR /&gt;DAT=`printf "%.378s\n" $LIN`&lt;BR /&gt;echo $DAT &amp;gt;&amp;gt; test&lt;BR /&gt;done&lt;BR /&gt;tr -d "[\015\012]" &amp;lt; test &amp;gt; testout&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;But this is giving me identical *82.txt and test files (no trailing white spaces)&lt;BR /&gt;I???ve seen hundreds of posting on getting rid of white spaces but nothing on injecting trailing chr(20).&lt;BR /&gt;I???ll appreciate any cmments. Thanks, Victor&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2002 15:05:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721527#M948079</guid>
      <dc:creator>Victor Pavon</dc:creator>
      <dc:date>2002-05-10T15:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721528#M948080</link>
      <description>Hi Victor,&lt;BR /&gt;I don't know how to check for fixed length string.&lt;BR /&gt;&lt;BR /&gt;But here is inserting blanck space&lt;BR /&gt;#insert 5 blank spaces at beginning of each line (make page offset)&lt;BR /&gt;sed 's/^/     /'&lt;BR /&gt;&lt;BR /&gt;Sachin</description>
      <pubDate>Fri, 10 May 2002 15:16:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721528#M948080</guid>
      <dc:creator>Sachin Patel</dc:creator>
      <dc:date>2002-05-10T15:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721529#M948081</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;While I would probably do this in perl of awk (it would be much faster), you can do it within the shell:&lt;BR /&gt;&lt;BR /&gt;Your:&lt;BR /&gt;DAT=`printf "%.378s\n" $LIN` &lt;BR /&gt;echo $DAT &amp;gt;&amp;gt; test &lt;BR /&gt;&lt;BR /&gt;becomes:&lt;BR /&gt;&lt;BR /&gt;DAT=$(printf '%-378.378s' "${LIN}")&lt;BR /&gt;echo "${DAT}" &amp;gt;&amp;gt; test&lt;BR /&gt;&lt;BR /&gt;Note that echo does an implicit linefeed so that no LF is needed in the printf. The quotes around ${DAT} are required to include the white space. I have also replaced your backticks with the more modern syntax $(command)&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2002 15:19:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721529#M948081</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-10T15:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721530#M948082</link>
      <description>Does this work?&lt;BR /&gt;&lt;BR /&gt;rm -f test &lt;BR /&gt;cat *82.txt | while read LIN &lt;BR /&gt;do &lt;BR /&gt;printf "%378.378s\n" $LIN &amp;gt;&amp;gt; test&lt;BR /&gt;done &lt;BR /&gt;tr -d "[\015\012]" &amp;lt; test &amp;gt; testout &lt;BR /&gt;exit &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan</description>
      <pubDate>Fri, 10 May 2002 15:19:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721530#M948082</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2002-05-10T15:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721531#M948083</link>
      <description>Sachin gave you half the answer.&lt;BR /&gt;&lt;BR /&gt;First sed the file to append a load of spaces to the end of each line, to guarantee more than 378 chars, then use your printf routine to chop everything back to 378 chars afterwards.&lt;BR /&gt;&lt;BR /&gt;$ is EOL in sed.  If you replace it with spaces it just adds the spaces before the EOL.&lt;BR /&gt;&lt;BR /&gt;sed 's/$/               loads of spaces on the end/' infile &amp;gt; outfile&lt;BR /&gt;&lt;BR /&gt;...printf "%.378s\n" $LIN`  etc as you did before.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2002 15:25:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721531#M948083</guid>
      <dc:creator>Steve Lewis</dc:creator>
      <dc:date>2002-05-10T15:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721532#M948084</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;here is a script of mine which formats the output of bdf while changing the values to MB's. The principle for formatting can be applied to your file.&lt;BR /&gt;&lt;BR /&gt;cheers&lt;BR /&gt;John.</description>
      <pubDate>Fri, 10 May 2002 15:29:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721532#M948084</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-10T15:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721533#M948085</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;here is a script of mine which formats the output of bdf while changing the values to MB's. The principle for formatting can be applied to your file.&lt;BR /&gt;&lt;BR /&gt;cheers&lt;BR /&gt;John.&lt;BR /&gt;&lt;BR /&gt;and again with the attachment</description>
      <pubDate>Fri, 10 May 2002 15:29:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721533#M948085</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-10T15:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721534#M948086</link>
      <description>Try this...&lt;BR /&gt;&lt;BR /&gt;rm testout&lt;BR /&gt;...&lt;BR /&gt;do&lt;BR /&gt;printf "%-378s" ${LIN} &amp;gt;&amp;gt; testout&lt;BR /&gt;done&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;No need for command substitution - printf direct to the file.&lt;BR /&gt;&lt;BR /&gt;No need to remove the linefeed because printf hasn't written one.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John</description>
      <pubDate>Fri, 10 May 2002 15:30:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721534#M948086</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2002-05-10T15:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Formating output to fixed lenght</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721535#M948087</link>
      <description>Ok Clay, I bite. How would the rest of the world awk this?&lt;BR /&gt;&lt;BR /&gt;Your solution works, great answer BTW!!!&lt;BR /&gt;&lt;BR /&gt;Victor</description>
      <pubDate>Fri, 10 May 2002 15:31:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/formating-output-to-fixed-lenght/m-p/2721535#M948087</guid>
      <dc:creator>Victor Pavon</dc:creator>
      <dc:date>2002-05-10T15:31:27Z</dc:date>
    </item>
  </channel>
</rss>

