bash - Write to output file if code from file 1 never matches code from file 2 -


i need help: have 2 files , need match lines of file 1 lines of file 2 based on first 2 columns (a b) in order create output file. both files have same structure not same content. wrote script , works fine. have additional problem: there cases code of file 1 (a b) never matches code of file 2. there option refer these cases well? sorry, i'm complete beginner...

here how code looks like:

#!/bin/bash while read file1     file1_line=( ${file1_lines[$counter_file1]} )     file1_a=${file1_line[0]}       file1_b=${file1_line[1]}     while read line_file2             file2_line=( ${file2_lines[$counter_file2]} )         file2_a=${file2_line[0]}            file2_b=${file2_line[1]}              if ["file1_a" == "file2_a"] && ["file1_b" == "file2_b"]                             echo "true"             else                 counter_file2=[counter_file2+1]             fi     done < $file2     counter_file2=0     counter_file1=$[counter_file1+1]  done 

there cases code of file 1 (a b) never matches code of file 2. there option refer these cases well?

you can set status flag inside inner while loop track if line found match or not. outside of inner loop, can handle special case.

i haven't tested it, should work:

#!/bin/bash while read file1     file1_line=( ${file1_lines[$counter_file1]} )     file1_a=${file1_line[0]}       file1_b=${file1_line[1]}      had_match=0     while read line_file2             file2_line=( ${file2_lines[$counter_file2]} )         file2_a=${file2_line[0]}            file2_b=${file2_line[1]}              if ["file1_a" == "file2_a"] && ["file1_b" == "file2_b"]                             had_match=1                 echo "true"             else                 counter_file2=[counter_file2+1]             fi     done < $file2      if (( had_match == 0 ));         # special here     fi      counter_file2=0     counter_file1=$[counter_file1+1]  done 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -