<?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: Can AWK read two files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539328#M701674</link>
    <description>this should get you close to what you want&lt;BR /&gt;&lt;BR /&gt;cat file2 | sort -u | awk '&lt;BR /&gt;BEGIN {&lt;BR /&gt;while ( getline var file1 &amp;gt; 0 )&lt;BR /&gt;  if ( var ~ /pattern1/ ) {&lt;BR /&gt;     x=substr();&lt;BR /&gt;  }&lt;BR /&gt;}}&lt;BR /&gt;/pattern2/ {&lt;BR /&gt;y=substr();&lt;BR /&gt;res= x - y;&lt;BR /&gt;if ( res ==2 ) ...&lt;BR /&gt;if ( res ==3 ) ...&lt;BR /&gt;)</description>
    <pubDate>Fri, 06 May 2005 13:10:36 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2005-05-06T13:10:36Z</dc:date>
    <item>
      <title>Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539324#M701670</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;Is there a way in which AWK reads two files, get a result from each file, and then subtracts file1 result from file2 result.&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;x=/= "RM_[0-9][0-9][0-9][0-9][0-9]/{print substr($3,2,10),substr($3,7,5) | "tail -n1"}' from file1&lt;BR /&gt;y={if($1~/^IP/ &amp;amp;&amp;amp; $9~/M_[0-9]/){print substr($9,1,10),substr($9,6,5)|"sort -u"}}' from file2&lt;BR /&gt;&lt;BR /&gt;res=(x[2]-y[2])&lt;BR /&gt;&lt;BR /&gt;then&lt;BR /&gt;{if(res ==3) {----&amp;gt; here we call a system call&lt;BR /&gt;}&lt;BR /&gt;else {if(res == 2)&lt;BR /&gt;    {----&amp;gt; here we call a system call}&lt;BR /&gt;    }&lt;BR /&gt;     }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;My x values is "Jack_00212 00212"&lt;BR /&gt;   y values is "Jack_00210 00210"&lt;BR /&gt;   &lt;BR /&gt;Many Thanks&lt;BR /&gt;Chris</description>
      <pubDate>Fri, 06 May 2005 09:08:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539324#M701670</guid>
      <dc:creator>Chris Frangandonis</dc:creator>
      <dc:date>2005-05-06T09:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539325#M701671</link>
      <description>General suggestion.&lt;BR /&gt;&lt;BR /&gt;I usually feed data into awk.&lt;BR /&gt;&lt;BR /&gt;&lt;SOME code=""&gt; | awk ... &lt;FURTHER processing=""&gt;&lt;BR /&gt;&lt;BR /&gt;Surely you can run do this:&lt;BR /&gt;&lt;BR /&gt;$result1=(&lt;SOME code=""&gt; | awk ... &lt;FURTHER processing=""&gt;)&lt;BR /&gt;&lt;BR /&gt;$result2=(&lt;SOME code=""&gt; | awk ... &lt;FURTHER processing=""&gt;)&lt;BR /&gt;&lt;BR /&gt;Then you can compare (subtract) the values in result1 and result2 variables.&lt;BR /&gt;&lt;BR /&gt;You could also redirect the output to files and use the diff command to compare the results.&lt;BR /&gt;&lt;BR /&gt;awk is merely a tool here. I don't think it can do the job itself, the job will get done with some thoughtful script design.&lt;BR /&gt;&lt;BR /&gt;I'd try and break it into smaller chunks.&lt;BR /&gt;&lt;BR /&gt;SEP&lt;/FURTHER&gt;&lt;/SOME&gt;&lt;/FURTHER&gt;&lt;/SOME&gt;&lt;/FURTHER&gt;&lt;/SOME&gt;</description>
      <pubDate>Fri, 06 May 2005 09:38:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539325#M701671</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2005-05-06T09:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539326#M701672</link>
      <description>Hi Steven,&lt;BR /&gt;&lt;BR /&gt;Thanks for your reply. Yes it was my initial plan, but I thought, why not learn from asking. I have seen AWK scripts doing this kind of method.&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;Chris&lt;BR /&gt;</description>
      <pubDate>Fri, 06 May 2005 09:44:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539326#M701672</guid>
      <dc:creator>Chris Frangandonis</dc:creator>
      <dc:date>2005-05-06T09:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539327#M701673</link>
      <description>Any reason you have to use awk?&lt;BR /&gt;&lt;BR /&gt;Perl could do it, or consider sed.</description>
      <pubDate>Fri, 06 May 2005 12:11:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539327#M701673</guid>
      <dc:creator>Scot Bean</dc:creator>
      <dc:date>2005-05-06T12:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539328#M701674</link>
      <description>this should get you close to what you want&lt;BR /&gt;&lt;BR /&gt;cat file2 | sort -u | awk '&lt;BR /&gt;BEGIN {&lt;BR /&gt;while ( getline var file1 &amp;gt; 0 )&lt;BR /&gt;  if ( var ~ /pattern1/ ) {&lt;BR /&gt;     x=substr();&lt;BR /&gt;  }&lt;BR /&gt;}}&lt;BR /&gt;/pattern2/ {&lt;BR /&gt;y=substr();&lt;BR /&gt;res= x - y;&lt;BR /&gt;if ( res ==2 ) ...&lt;BR /&gt;if ( res ==3 ) ...&lt;BR /&gt;)</description>
      <pubDate>Fri, 06 May 2005 13:10:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539328#M701674</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-05-06T13:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539329#M701675</link>
      <description>Hi Curt,&lt;BR /&gt;&lt;BR /&gt;Thanks. The only problem is that after the pattern search in both files, I only require the last line for both cases. Only then will I be able to subtract "x-y" and then use result in a "if" loop.&lt;BR /&gt;&lt;BR /&gt;Scot,&lt;BR /&gt;&lt;BR /&gt;My Perl knowledge is about 30%.&lt;BR /&gt;&lt;BR /&gt;Many Thanks&lt;BR /&gt;Chris&lt;BR /&gt;</description>
      <pubDate>Sat, 07 May 2005 04:00:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539329#M701675</guid>
      <dc:creator>Chris Frangandonis</dc:creator>
      <dc:date>2005-05-07T04:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can AWK read two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539330#M701676</link>
      <description>then something like this&lt;BR /&gt;&lt;BR /&gt;cat file2 | sort -u | awk '&lt;BR /&gt;BEGIN {&lt;BR /&gt;while ( getline var file1 &amp;gt; 0 )&lt;BR /&gt;if ( var ~ /pattern1/ ) {&lt;BR /&gt;x=substr();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;/pattern2/ {&lt;BR /&gt;y=substr();&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;res= x - y;&lt;BR /&gt;if ( res ==2 ) ...&lt;BR /&gt;if ( res ==3 ) ...&lt;BR /&gt;)</description>
      <pubDate>Sat, 07 May 2005 08:52:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-awk-read-two-files/m-p/3539330#M701676</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-05-07T08:52:52Z</dc:date>
    </item>
  </channel>
</rss>

