<?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 compare 2 files using AWK based on conditions in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710121#M659718</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am struck in the middle of a problem.&lt;BR /&gt;&lt;BR /&gt;I have a control file which tells me which are the fields in the files I need to compare and based on the values I need to print the exact value if key =Y and output is Y , or if output is Y/N then I need to print only Y if it matches or N if it does not match.&lt;BR /&gt;&lt;BR /&gt;For ex: &lt;BR /&gt;&lt;BR /&gt;my control file&lt;BR /&gt;&lt;BR /&gt;key|compare_field|output&lt;BR /&gt;Y|Field_1|Y&lt;BR /&gt;N|Filed_2|Y/N&lt;BR /&gt;Y|Field_3|Y&lt;BR /&gt;N|Field_4|Y/N&lt;BR /&gt;N|Field_5|N&lt;BR /&gt;N|Field_6|Y/N&lt;BR /&gt;&lt;BR /&gt;file1&lt;BR /&gt;&lt;BR /&gt;field_1|feld_2|field_3|field_4|field_5|field_6&lt;BR /&gt;000|adbc|edfr|hjkl|890|jlk|ioy&lt;BR /&gt;678|jfjd|djla|uopp|678|jyh|jkl&lt;BR /&gt;&lt;BR /&gt;file2&lt;BR /&gt;&lt;BR /&gt;field_1|feld_2|field_3|field_4|field_5|field_6&lt;BR /&gt;000|adbc|edfr|hjkl|890|jlk|ioy&lt;BR /&gt;678|juio|djla|uopu|678|jyh|jkl&lt;BR /&gt;&lt;BR /&gt;my output should be&lt;BR /&gt;&lt;BR /&gt;field_1|feld_2|field_3|field_4|field_6&lt;BR /&gt;000|Y|edfr|Y|Y&lt;BR /&gt;678|N|djfr|N|Y&lt;BR /&gt;&lt;BR /&gt;I can do it seperately, need your help to combine this logic.&lt;BR /&gt;&lt;BR /&gt;# to copy the field names as the header in the report file.&lt;BR /&gt;nawk -F\| 'END {print x } $NF =="Y" || $NF == "Y\/N" { printf "%s",$2 FS &amp;gt;&amp;gt; "report_file" }' control_file&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To compare the 2 files and print the output as Y or N&lt;BR /&gt;&lt;BR /&gt;nawk -F'|' '{ getline x &lt;F&gt;&lt;/F&gt; NR &amp;gt;1 {for(i=2;i&amp;lt;=NF;i++) $i=(F[i]==$i)?"Y";"N"}1' OFS="|" f=file2 file1&lt;BR /&gt;&lt;BR /&gt;I can do then seperately, but I am not able to read the control file and compare the files based on the control file.&lt;BR /&gt;&lt;BR /&gt;Please help me.&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance&lt;BR /&gt;Rashmi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 06 Nov 2010 18:13:42 GMT</pubDate>
    <dc:creator>chinnaga</dc:creator>
    <dc:date>2010-11-06T18:13:42Z</dc:date>
    <item>
      <title>compare 2 files using AWK based on conditions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710121#M659718</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am struck in the middle of a problem.&lt;BR /&gt;&lt;BR /&gt;I have a control file which tells me which are the fields in the files I need to compare and based on the values I need to print the exact value if key =Y and output is Y , or if output is Y/N then I need to print only Y if it matches or N if it does not match.&lt;BR /&gt;&lt;BR /&gt;For ex: &lt;BR /&gt;&lt;BR /&gt;my control file&lt;BR /&gt;&lt;BR /&gt;key|compare_field|output&lt;BR /&gt;Y|Field_1|Y&lt;BR /&gt;N|Filed_2|Y/N&lt;BR /&gt;Y|Field_3|Y&lt;BR /&gt;N|Field_4|Y/N&lt;BR /&gt;N|Field_5|N&lt;BR /&gt;N|Field_6|Y/N&lt;BR /&gt;&lt;BR /&gt;file1&lt;BR /&gt;&lt;BR /&gt;field_1|feld_2|field_3|field_4|field_5|field_6&lt;BR /&gt;000|adbc|edfr|hjkl|890|jlk|ioy&lt;BR /&gt;678|jfjd|djla|uopp|678|jyh|jkl&lt;BR /&gt;&lt;BR /&gt;file2&lt;BR /&gt;&lt;BR /&gt;field_1|feld_2|field_3|field_4|field_5|field_6&lt;BR /&gt;000|adbc|edfr|hjkl|890|jlk|ioy&lt;BR /&gt;678|juio|djla|uopu|678|jyh|jkl&lt;BR /&gt;&lt;BR /&gt;my output should be&lt;BR /&gt;&lt;BR /&gt;field_1|feld_2|field_3|field_4|field_6&lt;BR /&gt;000|Y|edfr|Y|Y&lt;BR /&gt;678|N|djfr|N|Y&lt;BR /&gt;&lt;BR /&gt;I can do it seperately, need your help to combine this logic.&lt;BR /&gt;&lt;BR /&gt;# to copy the field names as the header in the report file.&lt;BR /&gt;nawk -F\| 'END {print x } $NF =="Y" || $NF == "Y\/N" { printf "%s",$2 FS &amp;gt;&amp;gt; "report_file" }' control_file&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To compare the 2 files and print the output as Y or N&lt;BR /&gt;&lt;BR /&gt;nawk -F'|' '{ getline x &lt;F&gt;&lt;/F&gt; NR &amp;gt;1 {for(i=2;i&amp;lt;=NF;i++) $i=(F[i]==$i)?"Y";"N"}1' OFS="|" f=file2 file1&lt;BR /&gt;&lt;BR /&gt;I can do then seperately, but I am not able to read the control file and compare the files based on the control file.&lt;BR /&gt;&lt;BR /&gt;Please help me.&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance&lt;BR /&gt;Rashmi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 06 Nov 2010 18:13:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710121#M659718</guid>
      <dc:creator>chinnaga</dc:creator>
      <dc:date>2010-11-06T18:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 files using AWK based on conditions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710122#M659719</link>
      <description>For starters, you are not going to be able to do this in a one-liner.&lt;BR /&gt;&lt;BR /&gt;You'll need a BEGIN {} to read the control file, and store the results in an array indexed by the compare-field name.&lt;BR /&gt;&lt;BR /&gt;Unless you know the control file field names, and the column headers in the data file are garantueed to be in exact order you need to MAP those into column numbers. 'field_3' = column 3. To do that, as you read the first line of the data file you will want to create an other array for that mapping, or re-index that first array with the column numbers instead of names. And set a flag that this is done, or just use NR as you already do.&lt;BR /&gt;&lt;BR /&gt;With all in plase, then in the main loop with the flag set, or NR&amp;gt;1, you then for each record will have to loop over each field in do what needs to be done based on the control array.&lt;BR /&gt;&lt;BR /&gt;Q&amp;gt; where does "djfr" in the output come from?&lt;BR /&gt;&lt;BR /&gt;Q&amp;gt; how well can the column mnames expected to be matched: field_1 =? Field_1. feld_2 =? Filed_2,...&lt;BR /&gt;&lt;BR /&gt;Q&amp;gt; report on missing/excessive fields or ignore?&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Sat, 06 Nov 2010 18:48:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710122#M659719</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2010-11-06T18:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 files using AWK based on conditions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710123#M659720</link>
      <description>Thanks for the hint.. I will try based on your input.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot.</description>
      <pubDate>Sun, 07 Nov 2010 03:14:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710123#M659720</guid>
      <dc:creator>chinnaga</dc:creator>
      <dc:date>2010-11-07T03:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 files using AWK based on conditions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710124#M659721</link>
      <description>&amp;gt;Hein: You'll need a BEGIN {} to read the control file, and store the results in an array indexed by the compare-field name.&lt;BR /&gt;&lt;BR /&gt;It's worse than that.  There are three input files.  Unless file1 and file2 are in order and have the same number of records.&lt;BR /&gt;If so, as you cycle through file1, you can do a getline on file2.</description>
      <pubDate>Mon, 08 Nov 2010 03:22:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710124#M659721</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-11-08T03:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 files using AWK based on conditions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710125#M659722</link>
      <description>Dennis&amp;gt;&amp;gt; Unless file1 and file2 are in order and have the same number of records.&lt;BR /&gt;&lt;BR /&gt;Right. That was on other question I meant to ask. Are the input file garantueed to be in lock-step; are they sorted or can they be sorted; what to do if there are 'missing' or 'duplicate' records...; is one of the inputs 'dominant'?&lt;BR /&gt;&lt;BR /&gt;Q&amp;gt; can a single input line generate more than 1 output line ?&lt;BR /&gt;&lt;BR /&gt;and I suppose in the 'BEGIN' the script might as well slurp the first input line from each data file and do the column mapping right there to keep the main processing as clean as possible.&lt;BR /&gt;&lt;BR /&gt;If the example had been correct/plausible then I might have tried, but with all those variable/variants it seemed like 'real work'. &lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Nov 2010 04:10:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-files-using-awk-based-on-conditions/m-p/4710125#M659722</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2010-11-08T04:10:43Z</dc:date>
    </item>
  </channel>
</rss>

