LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Closed Thread
 
Search this Thread
Old 03-05-2010, 03:13 AM   #1
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 49

Rep: Reputation: 1
Question 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
 
Old 03-05-2010, 04:50 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi,

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

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

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
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
 
  


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 04:48 AM
URGENT----shell script to change word in file raghupal Programming 14 10-21-2008 01:49 AM
shell script to find an word or words from a line rakesh.tandur Linux - General 5 05-13-2008 02:57 PM
shell script: find subwords with 'compilation' word suresheva31 Programming 11 10-05-2005 05:17 AM
How to read ans parse MS word file using a Linux Shell script. Alek Linux - General 2 11-10-2003 03:07 PM


All times are GMT -5. The time now is 04:57 PM.

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