LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   word by word comparison in two files using loop in shell script (https://www.linuxquestions.org/questions/programming-9/word-by-word-comparison-in-two-files-using-loop-in-shell-script-793343/)

vaibhavs17 03-05-2010 02:13 AM

word by word comparison in two files using loop in shell script
 
Hi,

Suppose i have two files delimited by TAB.
File 1
======
1 B AB 2
2 C AB 3

File 2
=======
3 B AB 5
2 C AD 3

Output Should be::
Mismatch in file 1 and 2
first Line difference 1,3 and 2,5
second Line difference AB,AD.

Actually the problem is "How can i navigate in both the files at a same time" using any loop.
Using while loop i tried to navigate through both the files at a time.

[code] exec 3<File1.txt
exec 4<File2.txt

while IFS= read -r line1 <&3
IFS= read -r line2 <&4
do
echo "$line1"
echo "$line2"

done
[code]
but i want word by word comparision which requires word by word navigation then only i can get the output mentioned above.

Thanks,
Vaibhav

crts 03-05-2010 03:50 AM

Hi,

have you considered using 'diff' instead of writing your own comparison functions?

man diff

pixellany 03-05-2010 07:41 AM

This is a duplicate of your thread here:
http://www.linuxquestions.org/questi...script-793131/

Please do not post duplicate threads---you already have answers in the other one.

closed


All times are GMT -5. The time now is 10:09 AM.