Looping each row in file1.txt over all rows of file2.txt for comparing
<p>I have two text files, say file1.txt contains something like</p>

<p>100.145 10.0728</p>

<p>100.298 10.04</p>

<p>and file2.txt contains something like</p>

<p>100.223 8.92739</p>

<p>100.209 9.04269</p>

<p>100.084 9.08411</p>

<p>100.023 9.01252</p>

<p>I want to compare column 1 and column 2 of both files and print match if the difference of both columns in file1.txt and in file2.txt is less or equal to 0.001.</p>

<p>since both files don't have equal no. or rows, i want row1 of file1.txt to be compared with all the rows of file2.txt, then it will now pick row2 of file1.txt and do same until all rows of file1.txt are exhausted. Difference should like this ($1 file1.txt - $1 file2.txt) and ($2 file1.txt - $2 file2.txt) if difference of both is less or equal 0.001, it should print the rows in both file that match</p>

<p>you can try this;</p>

<pre><code>#!/bin/bash

while read line; do  
 while read line2; do  
    Col1F1=$(echo $line | awk '{print $1}')
    Col1F2=$(echo $line2 | awk '{print $1}')
    Col2F1=$(echo $line | awk '{print $2}')
    Col2F2=$(echo $line2 | awk '{print $2}')

        if [ ! -z "${Col1F1}" ] &amp;&amp; [ ! -z "${Col1F2}" ]; then

         diffCol1=$(awk '{print $1-$2}' &lt;&lt;&lt; "$Col1F1 $Col1F2")
         diffCol2=$(awk '{print $1-$2}' &lt;&lt;&lt; "$Col2F1 $Col2F2")

            if (( $(echo "$diffCol1 &lt; 0.001" |bc -l) &amp;&amp; $(echo "$diffCol2 &lt; 0.001" |bc -l))); then
                echo -e ${Col1F1} "\t" ${Col2F1} "\t" ${Col1F2} "\t" ${Col2F2} "\n"
            fi

        fi
 done &lt; file2.txt
done &lt; file1.txt
</code></pre>

python awk