LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 02:13 AM   #1
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

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, 03:50 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

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

man diff
 
Old 03-05-2010, 07:41 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 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
Open Source Consulting | Domain Registration