<?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: need to add trailing spaces to match fixed character length in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174096#M90910</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;leaving the best solution of Mounaam beside, your mistake is the mixing of a shell variable $j into awk, which is not possible in the way you did it.&lt;BR /&gt;1) Splice up the command string the shell parses&lt;BR /&gt;... | awk '{ printf $1&lt;BR /&gt;for (k=0; k&amp;lt;'$j'; k++) printf " " } ' ...&lt;BR /&gt;2) Supply an awk variable&lt;BR /&gt;... | awk -v j=$j '{ printf $1&lt;BR /&gt;for (k=0; k&lt;J&gt;&lt;/J&gt;&lt;BR /&gt;There are other constructs in you awk which make your solution break:&lt;BR /&gt;1) Dealing just with the printf() function without '\n' in the strings will result in one long line.&lt;BR /&gt;2) Having spaces in your line, only a part of the input will be copied.&lt;BR /&gt;&lt;BR /&gt;If this awk is part of a larger processing, I suggest this approach:&lt;BR /&gt;awk '{printf($0);for(k=length($0);k&amp;lt;145;k++) printf(" ");printf("\n")}' input &amp;gt;output&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
    <pubDate>Sat, 05 Apr 2008 06:19:25 GMT</pubDate>
    <dc:creator>Peter Nikitka</dc:creator>
    <dc:date>2008-04-05T06:19:25Z</dc:date>
    <item>
      <title>need to add trailing spaces to match fixed character length</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174092#M90906</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;My i/p file (INPUT) has 2 lines. First line has 41 chars and the second one has 100 chars.&lt;BR /&gt;I need to have fixed character length (145) in the all the lines of that file. I tried the below script but unable to pass the varaible 'j' in the for loop.&lt;BR /&gt;&lt;BR /&gt;i=0;&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;count=`echo $line | wc -c`&lt;BR /&gt;j=`expr 145 - $count`&lt;BR /&gt;echo "Char count is $count \n"&lt;BR /&gt;echo $line | awk '{ printf $1 &lt;BR /&gt;for (k=0; k&amp;lt;$j; k++)   printf " " } ' &amp;gt;&amp;gt; OUTPUT&lt;BR /&gt;done &amp;lt; INPUT&lt;BR /&gt;&lt;BR /&gt;NOTE : error comes due to "k&amp;lt;$j" used ...&lt;BR /&gt;&lt;BR /&gt;Can anybody please help me in this?&lt;BR /&gt;&lt;BR /&gt;Thanks &amp;amp; Regards,&lt;BR /&gt;Sathis Kumar.B&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Apr 2008 13:30:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174092#M90906</guid>
      <dc:creator>sathis kumar</dc:creator>
      <dc:date>2008-04-04T13:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: need to add trailing spaces to match fixed character length</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174093#M90907</link>
      <description>&lt;!--!*#--&gt;I only know simple-minded, crude ways to do&lt;BR /&gt;such things.&lt;BR /&gt;&lt;BR /&gt;td176&amp;gt; str='abc'&lt;BR /&gt;&lt;BR /&gt;td176&amp;gt; echo "&amp;gt;${str}&amp;lt;"&lt;BR /&gt;&amp;gt;abc&amp;lt;&lt;BR /&gt;&lt;BR /&gt;td176&amp;gt; strp=` echo "        $str" | sed -e 's/.*\(......\)$/\1/' `&lt;BR /&gt;&lt;BR /&gt;td176&amp;gt; echo "&amp;gt;${strp}&amp;lt;"&lt;BR /&gt;&amp;gt;   abc&amp;lt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But I have fun.</description>
      <pubDate>Fri, 04 Apr 2008 13:48:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174093#M90907</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-04-04T13:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: need to add trailing spaces to match fixed character length</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174094#M90908</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;example with Posix shell:&lt;BR /&gt;$ typeset -R8 a=123&lt;BR /&gt;$ typeset -L8 b=123&lt;BR /&gt;Result:&lt;BR /&gt;$ echo "|$a|\n|$b|"&lt;BR /&gt;|     123|&lt;BR /&gt;|123     |&lt;BR /&gt;&lt;BR /&gt;For your case:&lt;BR /&gt;$ typeset -L145 l&lt;BR /&gt;$ while read l;do echo $l;done &amp;lt; input &amp;gt; output</description>
      <pubDate>Fri, 04 Apr 2008 14:07:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174094#M90908</guid>
      <dc:creator>Mounaam</dc:creator>
      <dc:date>2008-04-04T14:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: need to add trailing spaces to match fixed character length</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174095#M90909</link>
      <description>Just use awk or perl or printf in the loop.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$IFS=""&lt;BR /&gt;$while read line&lt;BR /&gt;do&lt;BR /&gt;printf "%-145s\n" $line&lt;BR /&gt;done &amp;lt; INPUT&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;$ awk '{printf("%-80s\n",$0)}' INPUT &amp;gt; OUTPUT&lt;BR /&gt;&lt;BR /&gt;or by adding a piece of string in perl:&lt;BR /&gt;&lt;BR /&gt;$ perl -pe '$pad=q( )x(145-length); s/$/$pad/e' INPUT &amp;gt; OUTPUT&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;so many ways....&lt;BR /&gt;&lt;BR /&gt;All so much better than printing a character at a time until done.&lt;BR /&gt;&lt;BR /&gt;hth.&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Apr 2008 14:26:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174095#M90909</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-04-04T14:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: need to add trailing spaces to match fixed character length</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174096#M90910</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;leaving the best solution of Mounaam beside, your mistake is the mixing of a shell variable $j into awk, which is not possible in the way you did it.&lt;BR /&gt;1) Splice up the command string the shell parses&lt;BR /&gt;... | awk '{ printf $1&lt;BR /&gt;for (k=0; k&amp;lt;'$j'; k++) printf " " } ' ...&lt;BR /&gt;2) Supply an awk variable&lt;BR /&gt;... | awk -v j=$j '{ printf $1&lt;BR /&gt;for (k=0; k&lt;J&gt;&lt;/J&gt;&lt;BR /&gt;There are other constructs in you awk which make your solution break:&lt;BR /&gt;1) Dealing just with the printf() function without '\n' in the strings will result in one long line.&lt;BR /&gt;2) Having spaces in your line, only a part of the input will be copied.&lt;BR /&gt;&lt;BR /&gt;If this awk is part of a larger processing, I suggest this approach:&lt;BR /&gt;awk '{printf($0);for(k=length($0);k&amp;lt;145;k++) printf(" ");printf("\n")}' input &amp;gt;output&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Sat, 05 Apr 2008 06:19:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-add-trailing-spaces-to-match-fixed-character-length/m-p/4174096#M90910</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2008-04-05T06:19:25Z</dc:date>
    </item>
  </channel>
</rss>

