<?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: search string in awk program in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608525#M853891</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Why are you using grep within awk when awk can do pattern matching itself? Moreover, you are send a CONSTANT string into grep. You are always going to get the same answer!&lt;BR /&gt;&lt;BR /&gt;A better approach might be:&lt;BR /&gt;if ($0 ~ /#/)&lt;BR /&gt;  {&lt;BR /&gt;    printf("I found it\n")&lt;BR /&gt;  }&lt;BR /&gt;else&lt;BR /&gt;  {&lt;BR /&gt;    printf("Not there\n")&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;or if you already have your data in a named variable&lt;BR /&gt;if (job_code ~ /#/) &lt;BR /&gt;  {&lt;BR /&gt;&lt;BR /&gt;  }&lt;BR /&gt;or &lt;BR /&gt;if (job_code !~ /#/) # does not match&lt;BR /&gt;&lt;BR /&gt;Regards, Clay</description>
    <pubDate>Tue, 06 Nov 2001 21:17:30 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-11-06T21:17:30Z</dc:date>
    <item>
      <title>search string in awk program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608522#M853888</link>
      <description>Hi Folks,&lt;BR /&gt;&lt;BR /&gt;  I have to look for a particular charcter(#) in an awk variable (in awk program) and take decision based on it.&lt;BR /&gt;&lt;BR /&gt;for e.g (Part of my awk program)&lt;BR /&gt;&lt;BR /&gt;-----------------&lt;BR /&gt; if ( job_code != "" &amp;amp;&amp;amp; script != "" &amp;amp;&amp;amp; job_type != "" ) {&lt;BR /&gt; job_code1=system("echo "job_code"|grep  \"#\"")&lt;BR /&gt;   if (job_code1 != "" )&lt;BR /&gt;    {&lt;BR /&gt;       split(job_code,tag1,"#")&lt;BR /&gt;       job_code2=tag1[1]&lt;BR /&gt;       split(job_code2,tag2,"=")&lt;BR /&gt;       job_code=tag2[1]&lt;BR /&gt;       print "#/job_code="job_code"@"tolower(dbsid)"#hold#"&lt;BR /&gt;          }&lt;BR /&gt;  else {&lt;BR /&gt;       print "#/job_code="job_code"@"tolower(dbsid)&lt;BR /&gt;        }&lt;BR /&gt;       print "#/job_type="job_type&lt;BR /&gt;       print "#/script="script&lt;BR /&gt;---------------&lt;BR /&gt;&lt;BR /&gt;  for some reason, the variable job_type1 always not null. I have a suspicion that the command might be wrong. Can some body help me out. Thanks in adv.&lt;BR /&gt;&lt;BR /&gt;Kris</description>
      <pubDate>Tue, 06 Nov 2001 20:37:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608522#M853888</guid>
      <dc:creator>Kris_5</dc:creator>
      <dc:date>2001-11-06T20:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: search string in awk program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608523#M853889</link>
      <description>Whereis your first "IF's" closing "}"??&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Tue, 06 Nov 2001 20:53:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608523#M853889</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-11-06T20:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: search string in awk program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608524#M853890</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;The value of 'job_code1' will be the exit status of the 'system' command -- either &amp;lt;0&amp;gt; or &amp;lt;1&amp;gt;.  Does that help?&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 06 Nov 2001 20:53:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608524#M853890</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-11-06T20:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: search string in awk program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608525#M853891</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Why are you using grep within awk when awk can do pattern matching itself? Moreover, you are send a CONSTANT string into grep. You are always going to get the same answer!&lt;BR /&gt;&lt;BR /&gt;A better approach might be:&lt;BR /&gt;if ($0 ~ /#/)&lt;BR /&gt;  {&lt;BR /&gt;    printf("I found it\n")&lt;BR /&gt;  }&lt;BR /&gt;else&lt;BR /&gt;  {&lt;BR /&gt;    printf("Not there\n")&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;or if you already have your data in a named variable&lt;BR /&gt;if (job_code ~ /#/) &lt;BR /&gt;  {&lt;BR /&gt;&lt;BR /&gt;  }&lt;BR /&gt;or &lt;BR /&gt;if (job_code !~ /#/) # does not match&lt;BR /&gt;&lt;BR /&gt;Regards, Clay</description>
      <pubDate>Tue, 06 Nov 2001 21:17:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608525#M853891</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-11-06T21:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: search string in awk program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608526#M853892</link>
      <description>Not quite clear on what your looking to do but for what its worth...&lt;BR /&gt;&lt;BR /&gt;a great way to parse through a text file and use a variable in an awk statement to identify the line to perform a substitution on is to use the ENVIRON function.  For example, say you have a file called FILENAME. You wanted to search for all lines that had the contants of the HOST variable in its first field and based on that perform a substitution.  &lt;BR /&gt;&lt;BR /&gt;cat $FILENAME | awk -v var1="old" -v  var2="new" '&lt;BR /&gt;      (&lt;BR /&gt;      if ($1 == ENVIRON["HOST"])&lt;BR /&gt;      {&lt;BR /&gt;      sub(var1,var2);&lt;BR /&gt;      }&lt;BR /&gt;      print&lt;BR /&gt;      } ' &lt;BR /&gt;&lt;BR /&gt;Hope this helps!&lt;BR /&gt;&lt;BR /&gt;Tony</description>
      <pubDate>Tue, 06 Nov 2001 21:31:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-string-in-awk-program/m-p/2608526#M853892</guid>
      <dc:creator>Anthony deRito</dc:creator>
      <dc:date>2001-11-06T21:31:22Z</dc:date>
    </item>
  </channel>
</rss>

