Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Closed Thread
  Search this Thread
Old 03-05-2010, 02:13 AM   #1
Registered: Mar 2009
Posts: 51

Rep: Reputation: 1
Question word by word comparison in two files using loop in shell script


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
echo "$line1"
echo "$line2"

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

Old 03-05-2010, 03:50 AM   #2
Senior Member
Registered: Jan 2010
Posts: 1,863

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635

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

man diff
Old 03-05-2010, 07:41 AM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
This is a duplicate of your thread here:

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


Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i read two files word by word at a time using any loop by shell script? vaibhavs17 Programming 16 03-19-2010 03:48 AM
URGENT----shell script to change word in file raghupal Programming 14 10-21-2008 12:49 AM
shell script to find an word or words from a line rakesh.tandur Linux - General 5 05-13-2008 01:57 PM
shell script: find subwords with 'compilation' word suresheva31 Programming 11 10-05-2005 04:17 AM
How to read ans parse MS word file using a Linux Shell script. Alek Linux - General 2 11-10-2003 02:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration