<?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: ksh while read loop returns nothing in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739767#M655830</link>
    <description>First, I would treat all the lines as text which means $i is not the same as "$i". Start with the simplest loop:&lt;BR /&gt; &lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read i&lt;BR /&gt;do&lt;BR /&gt;echo "$i"&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;This should list the file contents (leading spaces truncated). If that works OK, then grep:&lt;BR /&gt; &lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read i&lt;BR /&gt;do&lt;BR /&gt;grep "$i" $TICKETS_COMPLETE_IN_WFMS_LOG&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;Now it is important to note that imbedded spaces and tabs (ie, white space) will NOT always compare equal. Are the strings in $TICKETS_IN_AC_LOG full of spaces? It would help by showing sample contents of both logs. I would extract 5-10 sample records from each and run grep manually until you get the desired results.&lt;BR /&gt; &lt;BR /&gt;Once your grep is working, you can simplify the script to just:&lt;BR /&gt; &lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read TEXT&lt;BR /&gt;do&lt;BR /&gt;[[ $(grep -c "$TEXT" $TICKETS_COMPLETE_IN_WFMS_LOG) -eq 0 ]] &amp;amp;&amp;amp;&lt;BR /&gt;echo "$TEXT" &amp;gt;&amp;gt; $TICKETS_MISMATCH&lt;BR /&gt;done&lt;BR /&gt;</description>
    <pubDate>Tue, 18 Jan 2011 02:09:24 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2011-01-18T02:09:24Z</dc:date>
    <item>
      <title>ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739761#M655824</link>
      <description>I am having a heck of at time on a while look in ksh.&lt;BR /&gt;I can cat the file in the script one step above and it returns data, on entry per line, but when I try to do a while loop, even the echo $i returns nothing.&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;cat $TICKETS_IN_AC_LOG&lt;BR /&gt;&lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read i&lt;BR /&gt;do &lt;BR /&gt;echo $i&lt;BR /&gt;var=`grep $i $TICKETS_COMPLETE_IN_WFMS_LOG`&lt;BR /&gt;if [[ $var -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;echo $i &amp;gt;&amp;gt;$TICKETS_MISMATCH&lt;BR /&gt;fi&lt;BR /&gt;done &lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Jan 2011 23:12:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739761#M655824</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2011-01-17T23:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739762#M655825</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] in ksh.&lt;BR /&gt;&lt;BR /&gt;On what?&lt;BR /&gt;&lt;BR /&gt;      uname -a&lt;BR /&gt;&lt;BR /&gt;You might find more people who would look at&lt;BR /&gt;a complete (small) test script than will try&lt;BR /&gt;to guess exactly what you're doing.</description>
      <pubDate>Mon, 17 Jan 2011 23:30:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739762#M655825</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-01-17T23:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739763#M655826</link>
      <description>&lt;!--!*#--&gt;This seems ok.  You can make some improvements on it:&lt;BR /&gt;while read i; do&lt;BR /&gt;   echo $i&lt;BR /&gt;   var=$(grep $i $TICKETS_COMPLETE_IN_WFMS_LOG)&lt;BR /&gt;   if [[ $var -eq 0 ]]; then&lt;BR /&gt;      echo $i &amp;gt;&amp;gt; $TICKETS_MISMATCH&lt;BR /&gt;   fi&lt;BR /&gt;done &amp;lt; $TICKETS_IN_AC_LOG&lt;BR /&gt;&lt;BR /&gt;That "if" is suspect.  You seem to be searching a file $TICKETS_COMPLETE_IN_WFMS_LOG for a record in $TICKETS_IN_AC_LOG and then checking it for the value 0.&lt;BR /&gt;Did you want to check the exit status instead?</description>
      <pubDate>Mon, 17 Jan 2011 23:40:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739763#M655826</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-01-17T23:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739764#M655827</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;This works for me:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;while read i&lt;BR /&gt;do&lt;BR /&gt;    echo ${i}&lt;BR /&gt;    var=$(grep -c "$i" ${TICKETS_COMPLETE_IN_WFMS_LOG})&lt;BR /&gt;    if [ ${var} -eq 0 ]; then&lt;BR /&gt;        echo ${i} &amp;gt;&amp;gt; ${TICKETS_MISMATCH}&lt;BR /&gt;    fi&lt;BR /&gt;done &amp;lt; ${TICKETS_IN_AC_LOG}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;...Notice that we changed the archaic backtick syntax to the POSIX $(...) notation to run a command.&lt;BR /&gt;&lt;BR /&gt;Too, the 'grep -c' returns the *count* of matched items which is then tested.  You weren't doing that correctly.&lt;BR /&gt;&lt;BR /&gt;Lastly, we eliminated the extraneous process --- the 'cat'.  The shell can do this (as shown) much more efficiently as I wrote it.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 17 Jan 2011 23:48:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739764#M655827</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-01-17T23:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739765#M655828</link>
      <description>yes, basically check to see if the record exists in $TICKETS_COMPLETE_IN_WFMS_LOG&lt;BR /&gt;&lt;BR /&gt;if it does, put that record in $TICKETS_MISMATCH</description>
      <pubDate>Tue, 18 Jan 2011 01:09:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739765#M655828</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2011-01-18T01:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739766#M655829</link>
      <description>This sure is puzzling...&lt;BR /&gt;while read i; do&lt;BR /&gt;   echo $i&lt;BR /&gt;   var=$(grep $i $TICKETS_COMPLETE_IN_WFMS_LOG)&lt;BR /&gt;   if [[ $var -eq 0 ]]; then&lt;BR /&gt;      echo $i &amp;gt;&amp;gt; $TICKETS_MISMATCH&lt;BR /&gt;   fi&lt;BR /&gt;done &amp;lt; $TICKETS_IN_AC_LOG&lt;BR /&gt;&lt;BR /&gt;Still wont echo line. and it returns nothing.</description>
      <pubDate>Tue, 18 Jan 2011 01:12:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739766#M655829</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2011-01-18T01:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739767#M655830</link>
      <description>First, I would treat all the lines as text which means $i is not the same as "$i". Start with the simplest loop:&lt;BR /&gt; &lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read i&lt;BR /&gt;do&lt;BR /&gt;echo "$i"&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;This should list the file contents (leading spaces truncated). If that works OK, then grep:&lt;BR /&gt; &lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read i&lt;BR /&gt;do&lt;BR /&gt;grep "$i" $TICKETS_COMPLETE_IN_WFMS_LOG&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;Now it is important to note that imbedded spaces and tabs (ie, white space) will NOT always compare equal. Are the strings in $TICKETS_IN_AC_LOG full of spaces? It would help by showing sample contents of both logs. I would extract 5-10 sample records from each and run grep manually until you get the desired results.&lt;BR /&gt; &lt;BR /&gt;Once your grep is working, you can simplify the script to just:&lt;BR /&gt; &lt;BR /&gt;cat $TICKETS_IN_AC_LOG|while read TEXT&lt;BR /&gt;do&lt;BR /&gt;[[ $(grep -c "$TEXT" $TICKETS_COMPLETE_IN_WFMS_LOG) -eq 0 ]] &amp;amp;&amp;amp;&lt;BR /&gt;echo "$TEXT" &amp;gt;&amp;gt; $TICKETS_MISMATCH&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Jan 2011 02:09:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739767#M655830</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2011-01-18T02:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: ksh while read loop returns nothing</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739768#M655831</link>
      <description>&lt;!--!*#--&gt;&amp;gt; This sure is puzzling...&lt;BR /&gt;&lt;BR /&gt;A complete test case might change that.&lt;BR /&gt;&lt;BR /&gt;Just a thought.</description>
      <pubDate>Tue, 18 Jan 2011 03:27:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-while-read-loop-returns-nothing/m-p/4739768#M655831</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-01-18T03:27:19Z</dc:date>
    </item>
  </channel>
</rss>

