<?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: Scripting question:  retaining spaces when looping read/echo statements in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087131#M717282</link>
    <description>It looks like you have a good solution.  I just wanted to add that you might try to typeset your variables as well.&lt;BR /&gt;&lt;BR /&gt;typeset -L20 CONTRACT&lt;BR /&gt;typeset -L60 SENDTO&lt;BR /&gt;&lt;BR /&gt;That would left justify and pad on the right w/ whitespace out to 20 or 60 respectively.  There is also the R equivalent as well.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 07 Oct 2003 13:03:35 GMT</pubDate>
    <dc:creator>Eric Buckner</dc:creator>
    <dc:date>2003-10-07T13:03:35Z</dc:date>
    <item>
      <title>Scripting question:  retaining spaces when looping read/echo statements</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087126#M717277</link>
      <description>Hoping someone can help.   I am attempting to write a simple loop that will echo or print the following 3 fields.   The problem I am having is that "echo" and "print" both seem to treat consecutive spaces as one space.  I'm used to using awk -F" " but as you can see the first field sometimes has spaces which is why I'm trying to use cut with character lengths. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Input file contains: &lt;BR /&gt;GA30494   0000      Y john_j_read@aul.com&lt;BR /&gt;GA620870220022      Y john_j_read@aul.com&lt;BR /&gt;&lt;BR /&gt;My loop:&lt;BR /&gt;cat extfile |while read line&lt;BR /&gt;do&lt;BR /&gt;CONTRACT=`echo $line |cut -c 1-20`&lt;BR /&gt;ACT=`echo $line |cut -c 21`&lt;BR /&gt;SENDTO=`echo $line |cut -c 22-82`&lt;BR /&gt;echo "${CONTRACT}" "${ACT}" "${SENDTO}"&lt;BR /&gt;done&lt;BR /&gt;GA30494 0000 Y john_ j _read@aul.com&lt;BR /&gt;GA620870220022 Y joh n _j_read@aul.com&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Notice that "cat" and cut are not the problem: &lt;BR /&gt;&lt;BR /&gt;#cat extfile |cut -c 1-20&lt;BR /&gt;GA30494   0000&lt;BR /&gt;GA620870220022&lt;BR /&gt;&lt;BR /&gt;#cat extfile |cut -c 21&lt;BR /&gt;Y&lt;BR /&gt;Y&lt;BR /&gt;&lt;BR /&gt;#cat extfile |cut -c 22-82&lt;BR /&gt; john_j_read@aul.com&lt;BR /&gt; john_j_read@aul.com&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;Thanks!   I'm willing to entertain other language options such as Perl!&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Oct 2003 11:49:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087126#M717277</guid>
      <dc:creator>John J Read</dc:creator>
      <dc:date>2003-10-07T11:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question:  retaining spaces when looping read/echo statements</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087127#M717278</link>
      <description>change your echo to printf&lt;BR /&gt;&lt;BR /&gt;printf "%s20 %1s %60s\n",$CONTRACT,$ACT,$SENDTO&lt;BR /&gt;&lt;BR /&gt;Should do the trick.&lt;BR /&gt;&lt;BR /&gt;--Jim&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Oct 2003 11:54:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087127#M717278</guid>
      <dc:creator>James Specht</dc:creator>
      <dc:date>2003-10-07T11:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question:  retaining spaces when looping read/echo statements</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087128#M717279</link>
      <description>Dag nabit!  It looks like this forum page also treats consective spaces as one space. It looked good when I cut/pasted it in but is collapsed it.  &lt;BR /&gt;&lt;BR /&gt;In the above post, the input file should look like: &lt;BR /&gt;&lt;BR /&gt;Field 1 is colums 1-20&lt;BR /&gt;Field 2 is column 21&lt;BR /&gt;Field 3 is colums 22-82&lt;BR /&gt;&lt;BR /&gt;GA30494   0000      Y john_j_read@aul.com&lt;BR /&gt;GA620870220022      Y john_j_read@aul.com&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Oct 2003 11:59:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087128#M717279</guid>
      <dc:creator>John J Read</dc:creator>
      <dc:date>2003-10-07T11:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question:  retaining spaces when looping read/echo statements</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087129#M717280</link>
      <description>Try to pass the strings as ONE arg to echo. E.g. echo "$line" with quotes.</description>
      <pubDate>Tue, 07 Oct 2003 12:06:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087129#M717280</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2003-10-07T12:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question:  retaining spaces when looping read/echo statements</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087130#M717281</link>
      <description>Thanks!   I was working out the new printf lines when I saw Dietmar's post. &lt;BR /&gt;&lt;BR /&gt;I'll give you both 10's!   &lt;BR /&gt;&lt;BR /&gt;Looks like putting quotes around $line is the easiest answer for me! &lt;BR /&gt;&lt;BR /&gt;It worked!  Thanks very much!!!&lt;BR /&gt;&lt;BR /&gt;cat extfile |while read line&lt;BR /&gt;do&lt;BR /&gt;CONTRACT=`echo "$line" |cut -c 1-20`&lt;BR /&gt;ACT=`echo "$line" |cut -c 21`&lt;BR /&gt;SENDTO=`echo "$line" |cut -c 22-82`&lt;BR /&gt;&lt;BR /&gt;echo "${CONTRACT}" "${ACT}" "${SENDTO}"&lt;BR /&gt;done</description>
      <pubDate>Tue, 07 Oct 2003 12:16:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087130#M717281</guid>
      <dc:creator>John J Read</dc:creator>
      <dc:date>2003-10-07T12:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question:  retaining spaces when looping read/echo statements</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087131#M717282</link>
      <description>It looks like you have a good solution.  I just wanted to add that you might try to typeset your variables as well.&lt;BR /&gt;&lt;BR /&gt;typeset -L20 CONTRACT&lt;BR /&gt;typeset -L60 SENDTO&lt;BR /&gt;&lt;BR /&gt;That would left justify and pad on the right w/ whitespace out to 20 or 60 respectively.  There is also the R equivalent as well.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Oct 2003 13:03:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question-retaining-spaces-when-looping-read-echo/m-p/3087131#M717282</guid>
      <dc:creator>Eric Buckner</dc:creator>
      <dc:date>2003-10-07T13:03:35Z</dc:date>
    </item>
  </channel>
</rss>

