LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 10-30-2009, 08:44 PM   #1
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Rep: Reputation: 15
vimdiff problem comparing two files


hello guys. im kind of embarrassed for asking this, but its driving me nuts.
im trying to compare two files with vimdiff, and vimdiff places a lot of hiffens ( i think it means that its because these lines doesnt appear on the other file ) but the thing is : the files are too simple to have this problem.

im not sure if i made myself clear, so ill post my results:

Quote:
leecher@darkstar:~/prog/uva/103$ cat out
5
10 11 2 1 3
4
5 3 4 2
Quote:
leecher@darkstar:~/prog/uva/103$ cat saida_uva
6
10 9 4 13 17 3
5
6 8 3 4 2
when i use vimdiff (with -o), it shows me this:

--------------------(the hiffens i talked about)
--------------------
5
10 11 2 1 3
4
5 3 4 2





6
10 9 4 13 17 3
5
6 8 3 4 2
-----------------(damn hiffens here again)
------------------

sorry for such a question, and yes, i know, i could just compare them manually, but ill need vimdiff for larger files. these are just some tests, and they are causing me trouble. thx


in case someone is wondering, here is the output of diff:

Quote:
leecher@darkstar:~/prog/uva/103$ diff out saida_uva
0a1,2
> 6
> 10 9 4 13 17 3
2,4c4
< 10 11 2 1 3
< 4
< 5 3 4 2
---
> 6 8 3 4 2
 
Old 10-30-2009, 10:06 PM   #2
aus9
Senior Member
 
Registered: Oct 2003
Location: Australia
Posts: 4,258

Rep: Reputation: Disabled
hi

I use xxdiff.....command is xxdiff file1 file2

its a lot easier to see the differences and so I hope gives you a better answer
 
Old 10-31-2009, 05:22 AM   #3
Vrajgh
Member
 
Registered: Aug 2005
Posts: 61

Rep: Reputation: 20
diff is mostly a line oriented comparison. In this case it sees the line containing only "5" and tries to line them up in both files. Having lined those up, the hyphens represent non-existent lines before one file and after the other.

It doesn't simply compare line 1 with line 1 etc because it needs to be able to detect where lines have been added or deleted.

diff produces:

Code:
$ diff -y out.txt out1.txt 
		   >	6
		   >	10 9 4 13 17 3
5			5
10 11 2 1 3	   |	6 8 3 4 2 
4		   <
5 3 4 2 	   <

<
The first and second line can be interpreted as existing only in the second file. The third line is the same in both. Fourth is a modified line. Last two lines exist only in the first file.

Basically, these files are too simple for diff to work out what to do with them.

I have never used xxdiff so can't say if it would produce better output.
 
Old 10-31-2009, 08:54 AM   #4
aus9
Senior Member
 
Registered: Oct 2003
Location: Australia
Posts: 4,258

Rep: Reputation: Disabled
http://imagebin.org/69888

I deliberately resized xxdiff smallish so it fitted under command but IMHO vision is better no need to explain it

image disappears from server in 7 days
 
Old 10-31-2009, 09:49 AM   #5
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Vrajgh View Post
diff is mostly a line oriented comparison. In this case it sees the line containing only "5" and tries to line them up in both files. Having lined those up, the hyphens represent non-existent lines before one file and after the other.

It doesn't simply compare line 1 with line 1 etc because it needs to be able to detect where lines have been added or deleted.

diff produces:

Code:
$ diff -y out.txt out1.txt 
		   >	6
		   >	10 9 4 13 17 3
5			5
10 11 2 1 3	   |	6 8 3 4 2 
4		   <
5 3 4 2 	   <

<
The first and second line can be interpreted as existing only in the second file. The third line is the same in both. Fourth is a modified line. Last two lines exist only in the first file.

Basically, these files are too simple for diff to work out what to do with them.

I have never used xxdiff so can't say if it would produce better output.

thx for the explanation. is there a way to disable this feature, or another utility program that only compares line per line?
 
Old 11-02-2009, 07:41 AM   #6
berbae
Member
 
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 530

Rep: Reputation: 50
If all the lines are different, as shown in your example, I don't think that vimdiff, or some other diff program, is the right way to cope with your problem.
Be more clear about what may differ in the files you want to compare, and about what you want the comparison for.
What do you intend to do ?
 
Old 11-02-2009, 07:00 PM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Just fyi hiffens => hyphens ; your spelling threw me for a minute there
 
Old 11-04-2009, 03:44 PM   #8
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by berbae View Post
If all the lines are different, as shown in your example, I don't think that vimdiff, or some other diff program, is the right way to cope with your problem.
Be more clear about what may differ in the files you want to compare, and about what you want the comparison for.
What do you intend to do ?
not all lines are different. only some of them. i need to comapre the output of my programs with the correct output. like i said, this example is silly.


Quote:
Just fyi hiffens => hyphens ; your spelling threw me for a minute there
don't remember very well, but i think i used the spell check b4 posting.
 
Old 11-05-2009, 04:37 AM   #9
berbae
Member
 
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 530

Rep: Reputation: 50
To visually check the differences, you can try :
Code:
pr -mT file1 file2
5                                   6
10 11 2 1 3                         10 9 4 13 17 3
4                                   5
5 3 4 2                             6 8 3 4 2
Is this of some help ?

Or something like that :
Code:
sed '{R file2
a \

}' file1
5
6

10 11 2 1 3
10 9 4 13 17 3

4
5

5 3 4 2
6 8 3 4 2
Or provide more precise example of the contents of the files.

Last edited by berbae; 11-05-2009 at 05:01 AM.
 
Old 11-13-2009, 07:09 PM   #10
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by berbae View Post
To visually check the differences, you can try :
Code:
pr -mT file1 file2
5                                   6
10 11 2 1 3                         10 9 4 13 17 3
4                                   5
5 3 4 2                             6 8 3 4 2
Is this of some help ?

Or something like that :
Code:
sed '{R file2
a \

}' file1
5
6

10 11 2 1 3
10 9 4 13 17 3

4
5

5 3 4 2
6 8 3 4 2
Or provide more precise example of the contents of the files.
sorry for the delay in my response. i tried pr and sed, but they show equal lines as well. i'll try to clarify my needs again.

basically, what i want is a program that compares line per line. if ith line from file1 differs from ith line from file2, print i(the line number, so i cant check them).

i checked a little bit the internet, and i found cmp and comm, but these don't do exactly what i want. cmp print differing bytes, and comm needs the lines to be sorted. like Vrajgh, diff doesn't work because it's a utility that is used mostly to compare the same file, but from different versions, with some modifications; it does this to generate a patch. diff works for some of my files, given their size and relatively small number of differences, but fails in the examples i gave. still, i'd like to have something that works always for my files.

the program i want is easy to implement, but i need to check files not only in my pc, so i was looking for some program that comes in most linux distros. sed seems to be enough, but i don't know how to use it( i'm n00b, remember), so if some1 can post a sed expression that does what i need, it would help me a lot.

besides what i said above, really thx in advance to all of you guys, who helped me 'till now, even in such a silly question.
 
Old 11-14-2009, 08:54 AM   #11
berbae
Member
 
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 530

Rep: Reputation: 50
Continuing to use the pr command :
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) print NR}'
only prints the line numbers of the different lines.
and
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) printf("%s\n%s\n\n",$1,$2)}'
prints the different lines together.

I used the ! as field separator, but you should use a character which doesn't appear in the files.

I tested it with :
file1
Code:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
file2
Code:
1
1 2
1 3 2
1 2 3 4
1 2 3 4 5
1 2 4 3 5 6
1 2 3 4 5 6 7
1 2 3 4 5 7 6 8
1 2 3 4 5 6 7 8 9
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) print NR}'
3
6
8
and
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) printf("%s\n%s\n\n",$1,$2)}'
1 2 3
1 3 2

1 2 3 4 5 6
1 2 4 3 5 6

1 2 3 4 5 6 7 8
1 2 3 4 5 7 6 8
I don't know if that is the answer to your problem, but what I suggest gives what you tell you are looking for.
You didn't provide a real example of the structure of the files you want to compare, so I had to guess with what I present here.
 
Old 12-04-2009, 03:22 PM   #12
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by berbae View Post
Continuing to use the pr command :
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) print NR}'
only prints the line numbers of the different lines.
and
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) printf("%s\n%s\n\n",$1,$2)}'
prints the different lines together.

I used the ! as field separator, but you should use a character which doesn't appear in the files.

I tested it with :
file1
Code:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
file2
Code:
1
1 2
1 3 2
1 2 3 4
1 2 3 4 5
1 2 4 3 5 6
1 2 3 4 5 6 7
1 2 3 4 5 7 6 8
1 2 3 4 5 6 7 8 9
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) print NR}'
3
6
8
and
Code:
pr -mTs! file1 file2|awk -F! '{if ($1 != $2) printf("%s\n%s\n\n",$1,$2)}'
1 2 3
1 3 2

1 2 3 4 5 6
1 2 4 3 5 6

1 2 3 4 5 6 7 8
1 2 3 4 5 7 6 8
I don't know if that is the answer to your problem, but what I suggest gives what you tell you are looking for.
You didn't provide a real example of the structure of the files you want to compare, so I had to guess with what I present here.
hey guys, long time no see . the above is exactly what i need! really thx to all of u and ur patience!!
 
  


Reply

Tags
diff


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing two files problem caponewgp Linux - Newbie 5 09-17-2009 02:20 PM
Comparing text files... jong357 Slackware 14 03-31-2007 04:29 PM
comparing lots of files Frustin Linux - General 4 09-22-2005 02:54 PM
Comparing files contents? hhegab Linux - Newbie 3 07-01-2004 12:45 AM
Comparing 2 Files xianzai Programming 2 05-23-2004 11:50 AM


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

Main Menu
 
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
Open Source Consulting | Domain Registration