<?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: Grep not functioning inside for/next or while loops. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890491#M771371</link>
    <description>Thanks for your efforts guys, but still getting the same result.&lt;BR /&gt;&lt;BR /&gt;Yang..I still get the grep mysterously not working.&lt;BR /&gt;&lt;BR /&gt;Peter... the data is a list of IP address, as they are kept in a variable rather than a file, I beleive echo is the correct command&lt;BR /&gt;The semi colon takes place of a line break, as such I don't think it is required.&lt;BR /&gt;&lt;BR /&gt;spex, I tried your awk command, and got exactly the same result..which is good as it means that the problem is not with grep or awk, but bad because I still don't have a clue while simple commands are not working.&lt;BR /&gt;</description>
    <pubDate>Wed, 01 Nov 2006 07:56:12 GMT</pubDate>
    <dc:creator>Johnny McKenzie</dc:creator>
    <dc:date>2006-11-01T07:56:12Z</dc:date>
    <item>
      <title>Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890486#M771366</link>
      <description>For reasons I don't understand the below grep statement does not generate output.&lt;BR /&gt;&lt;BR /&gt;Outside a while or for/next loop, works fine, and inside the loop the shell knows of all the variables ( the echo statements ) &lt;BR /&gt;But it simply will not generate output&lt;BR /&gt;&lt;BR /&gt;If I change the $HOSTSFILE variable to an invalid directory, grep generates errors, so it is probally working, but I can't fathom where the output might be going. This is slowly driving me insane, while my project falls further behind. Any thoughts gratefully recieved&lt;BR /&gt;&lt;BR /&gt;HP-UX B.11.00&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/posix/sh&lt;BR /&gt;&lt;BR /&gt;echo "$CONFIGCHG" | while read X ;do&lt;BR /&gt;         echo "$X"; echo "$HOSTSFILE"  &lt;BR /&gt;         grep "$X" "$HOSTSFILE" | awk '{print $2}'&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;gives me this result:&lt;BR /&gt;&lt;BR /&gt;$ storeconfig&lt;BR /&gt;138.27.120.94&lt;BR /&gt;/home/hynesm/bin/hosts&lt;BR /&gt;138.7.100.94&lt;BR /&gt;/home/hynesm/bin/hosts&lt;BR /&gt;&lt;BR /&gt;echo statements work fine, but no result from the grep statement.&lt;BR /&gt;While directly on the command line, works fine.&lt;BR /&gt;&lt;BR /&gt;$ HOSTSFILE="/home/hynesm/bin/hosts"&lt;BR /&gt;$ X=138.7.100.94&lt;BR /&gt;$ &lt;BR /&gt;$ grep "$X" "$HOSTSFILE" | awk '{print $2}'&lt;BR /&gt;TST-RMC-2R1&lt;BR /&gt;$ &lt;BR /&gt;&lt;BR /&gt;Exactly what I would expect. Is grep working, and if so where is it sending it's output.</description>
      <pubDate>Wed, 01 Nov 2006 06:31:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890486#M771366</guid>
      <dc:creator>Johnny McKenzie</dc:creator>
      <dc:date>2006-11-01T06:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890487#M771367</link>
      <description>Try:&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/posix/sh&lt;BR /&gt;&lt;BR /&gt;while read X&lt;BR /&gt;do&lt;BR /&gt;   echo "$X"&lt;BR /&gt;   echo "$HOSTSFILE" &lt;BR /&gt;   grep "$X" "$HOSTSFILE" | awk '{print $2}'&lt;BR /&gt;done &amp;lt; $CONFIGCHG&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang</description>
      <pubDate>Wed, 01 Nov 2006 06:45:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890487#M771367</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-11-01T06:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890488#M771368</link>
      <description>Hi,&lt;BR /&gt;what data is the while loop reading ?&lt;BR /&gt;Should the echo "$CONFIGCHG" be a cat "$CONFIGCHG"? Are there some semi-colons missing after echo "$HOSTSFILE".</description>
      <pubDate>Wed, 01 Nov 2006 06:45:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890488#M771368</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-11-01T06:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890489#M771369</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You probably want to 'cat $CONFIGCHG' rather than echo it.  You can also combine the 'grep ... | awk ...' command into a single awk program:&lt;BR /&gt;&lt;BR /&gt;awk "/$X/{print \$2}" $HOSTSFILE&lt;BR /&gt;&lt;BR /&gt;PCS&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Nov 2006 07:33:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890489#M771369</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2006-11-01T07:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890490#M771370</link>
      <description>- Missing semicolon?&lt;BR /&gt;- Do you need all those double quotes?&lt;BR /&gt;- Why not combine stuff?&lt;BR /&gt;&lt;BR /&gt;I think the whoe script can be re-written as:&lt;BR /&gt;&lt;BR /&gt;grep -f $CONFIGCHG $HOSTSFILE | awk '{print $2}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And if you do need the loop for other reasons, then you can have AWK alone do the job. For example&lt;BR /&gt;&lt;BR /&gt;awk -v x=$X '($1 ~ x){print $2}'&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Nov 2006 07:45:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890490#M771370</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-11-01T07:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890491#M771371</link>
      <description>Thanks for your efforts guys, but still getting the same result.&lt;BR /&gt;&lt;BR /&gt;Yang..I still get the grep mysterously not working.&lt;BR /&gt;&lt;BR /&gt;Peter... the data is a list of IP address, as they are kept in a variable rather than a file, I beleive echo is the correct command&lt;BR /&gt;The semi colon takes place of a line break, as such I don't think it is required.&lt;BR /&gt;&lt;BR /&gt;spex, I tried your awk command, and got exactly the same result..which is good as it means that the problem is not with grep or awk, but bad because I still don't have a clue while simple commands are not working.&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Nov 2006 07:56:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890491#M771371</guid>
      <dc:creator>Johnny McKenzie</dc:creator>
      <dc:date>2006-11-01T07:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890492#M771372</link>
      <description>OK, if $CONFIGCHG is variable, then this one may work:&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/posix/sh&lt;BR /&gt;&lt;BR /&gt;for $X in $CONFIGCHG&lt;BR /&gt;do&lt;BR /&gt;   echo "$X"&lt;BR /&gt;   echo "$HOSTSFILE"&lt;BR /&gt;   grep "$X" "$HOSTSFILE" | awk '{print $2}'&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang</description>
      <pubDate>Wed, 01 Nov 2006 08:28:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890492#M771372</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-11-01T08:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890493#M771373</link>
      <description>Hi,&lt;BR /&gt;change the $X to X in Yangs code and it works:&lt;BR /&gt;for $X in $CONFIGCHG&lt;BR /&gt;to&lt;BR /&gt;for X in $CONFIGCHG&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Nov 2006 08:36:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890493#M771373</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-11-01T08:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890494#M771374</link>
      <description>Spotted that, but it still dosn't work. &lt;BR /&gt;I appreciate the code is correct and it works on your machines, but there is obviously something mysterous going on with the box I'm working on.&lt;BR /&gt;&lt;BR /&gt;As neither grep nor awk return results, the question is now:&lt;BR /&gt;&lt;BR /&gt;"Why dosn't my shell show std output from inside loops ?"</description>
      <pubDate>Wed, 01 Nov 2006 09:23:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890494#M771374</guid>
      <dc:creator>Johnny McKenzie</dc:creator>
      <dc:date>2006-11-01T09:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890495#M771375</link>
      <description>Let's "debug" your script. Can you add "set -x" on top of yor script and run it again. Or do add "set -x" but run script with sh -x &amp;lt;script_name&amp;gt;. Hope you will find something interesting.&lt;BR /&gt;&lt;BR /&gt;Yang</description>
      <pubDate>Wed, 01 Nov 2006 09:45:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890495#M771375</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-11-01T09:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890496#M771376</link>
      <description>A long shot, but it may be a path problem, try your script with full paths for commands.&lt;BR /&gt;/usr/bin/grep or /usr/bin/awk</description>
      <pubDate>Wed, 01 Nov 2006 10:01:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890496#M771376</guid>
      <dc:creator>Christian Tremblay</dc:creator>
      <dc:date>2006-11-01T10:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890497#M771377</link>
      <description>it appears that the "read" isn't parsing the ip addresses, so the grep is trying to match all of them at once. I get the same results.&lt;BR /&gt;&lt;BR /&gt;the following appears to work as desired:&lt;BR /&gt;&lt;BR /&gt;for X in `echo $CONFIGCHG`; do&lt;BR /&gt;echo ${X}&lt;BR /&gt;grep ${X} ${HOSTSFILE} | awk '{print $2}'&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Nov 2006 10:44:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890497#M771377</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2006-11-01T10:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890498#M771378</link>
      <description>I get the same result inside a for/next loop as with a read statement.&lt;BR /&gt;&lt;BR /&gt;I tried the full paths, but with the same result.&lt;BR /&gt;&lt;BR /&gt;I'm convinced this is something weird with the setup on the HP Box, and not with the code. All the examples provided should work.&lt;BR /&gt;&lt;BR /&gt;I can't get anybody who looks after that box, to give me any time at all, so I'm thinking of going back to my orginal idea of using a LINUX/Bash enviroment. &lt;BR /&gt;&lt;BR /&gt;Just have to convince my boss it's not "shareware" ( Corprates are weird, unless they spent thousands of quid on something, it's "worthless" )&lt;BR /&gt;&lt;BR /&gt;Thanks for all your help, but this one is going into the "too hard" basket.</description>
      <pubDate>Wed, 01 Nov 2006 11:14:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890498#M771378</guid>
      <dc:creator>Johnny McKenzie</dc:creator>
      <dc:date>2006-11-01T11:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890499#M771379</link>
      <description>Re-read the last batch of posts.&lt;BR /&gt;&lt;BR /&gt;If CONFIGCHG contains more than one ip, for example:&lt;BR /&gt;123.234.123.1 123.234.222.111&lt;BR /&gt;it won't work with the following&lt;BR /&gt;&lt;BR /&gt;echo $CONFIGCHK | while read X; do&lt;BR /&gt;&lt;BR /&gt;the X gets the entire list, not the first IP.  Changing it to&lt;BR /&gt;&lt;BR /&gt;for X in $CONFIGCHK; do&lt;BR /&gt;&lt;BR /&gt;appears to work as desired.....</description>
      <pubDate>Wed, 01 Nov 2006 12:09:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890499#M771379</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2006-11-01T12:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890500#M771380</link>
      <description>also, as noted above,&lt;BR /&gt;&lt;BR /&gt;set -x at the beginning of your script to see how things are actually expanding.....</description>
      <pubDate>Wed, 01 Nov 2006 12:11:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890500#M771380</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2006-11-01T12:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890501#M771381</link>
      <description>Just one more thing to try.&lt;BR /&gt;&lt;BR /&gt;Change your script to pipe the output of "echo $X" into "od" command with suitable options. Inspect for invisible characters, which might make it difficult for grep to find a match.&lt;BR /&gt;&lt;BR /&gt;If the problem is there, re-think the way you're using to create the value of $CONFIGCHG.&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Nov 2006 12:13:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890501#M771381</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2006-11-01T12:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890502#M771382</link>
      <description>Can you run your script in debug mode by appending "-x" to the end of the first line and echo the value of $CONFIGCHG and post it here. i.e.&lt;BR /&gt;&lt;BR /&gt;echo $CONFIGCHG&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/posix/sh -x&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;rest of script&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.</description>
      <pubDate>Wed, 01 Nov 2006 12:23:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890502#M771382</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-11-01T12:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Grep not functioning inside for/next or while loops.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890503#M771383</link>
      <description>John,&lt;BR /&gt;&lt;BR /&gt;try changeing your read statement to &lt;BR /&gt;"read X junk;".&lt;BR /&gt;&lt;BR /&gt;I beleive the read command will load variables in sequence as they are contained in the line so that&lt;BR /&gt;read X makes X = the entire line&lt;BR /&gt;read X Y makes X = 1st word and Y = the rest of line&lt;BR /&gt;read X Y Z makes X = 1st, Y = 2nd and Z = rest of line.&lt;BR /&gt;&lt;BR /&gt;RayB</description>
      <pubDate>Thu, 02 Nov 2006 08:33:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-not-functioning-inside-for-next-or-while-loops/m-p/3890503#M771383</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2006-11-02T08:33:15Z</dc:date>
    </item>
  </channel>
</rss>

