LinuxQuestions.org
Visit Jeremy's Blog.
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

Reply
 
Search this Thread
Old 04-03-2008, 10:40 PM   #1
just.srad
Member
 
Registered: Apr 2008
Location: Singapore
Distribution: Slackware 14.0
Posts: 126

Rep: Reputation: 15
Question on diff command


Hi,

Based on my experimentation on the diff command, the contents in two files need not be in alphabetical order.

As long as a similar entry is found in the two file, the output of diff command will not show anything.

However, but i;m not so convinced of my conclusion, because, when i did a diff on two files for my inventory record (one is we do a manual record and the other is captured by the server).

The diff output shows "<" and ">" for a similar entry. Not sure whether i need to sort the two files first before i do a diff .

Thanks for any advise .

Justin
 
Old 04-03-2008, 11:31 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
If the files are different, diff should report that. Can you post samples of the data and the diff command line that you used please?
 
Old 04-03-2008, 11:35 PM   #3
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
In It before diff. doing fact, files is lead necessary not often results. so sort to to undesirable using will

Also, are you sure the files are really identical? Maybe they differ in some invisible way like trailing spaces.
 
Old 04-04-2008, 05:06 AM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,750

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
Diff uses 'fuzz' and 'context' settings that control how much change is needed for it to be reported.
First, try creating your diffs by using one or most of the most common options -usually you should use something like 'diff -pruN file1 file2' . I use these options nearly always because they are easy to remember and create more readable diffs. 'Context' refers to how many lines are included before and after the changed lines -this is normally 3 lines before and after. This helps the changes to be correctly applied when using the patch utility to apply the diffs/patches. 'patch' has an '-l' option which ignores changes in whitespace when applying patches(example: if you change a file by replacing TAB characters with 5 spaces then patch will ignore the changes).
If you are using diff to compare changes between lists of items which you consider sorting, then diff is probably not the program you should be using. 'cmp' or 'comm' would probably be better suited. diff is usally used to create patches or dif files which are meant to update source-code files to newer versions.
 
Old 04-05-2008, 04:01 AM   #5
just.srad
Member
 
Registered: Apr 2008
Location: Singapore
Distribution: Slackware 14.0
Posts: 126

Original Poster
Rep: Reputation: 15
Thanks for all the feedbacks and suggestions...

I discovered there's a file with two similar entries..

I sort the two files first and then remove the multiple entries using
"sort" command.

sort file1 > file_sort
sort file_sort | uniq > file_final

I did using the above command to the two files before using the diff
command.

Somehow i think because of the multiple entries cause the result to be unexpected .

Anyway , really appreciate for all the prompt response here. =)
 
  


Reply


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
creating a recursive DIFF command OtisLinux Linux - Newbie 3 08-13-2007 07:34 PM
How to avoid some differences in Diff command rajbal Linux - General 3 04-10-2007 11:28 PM
How to use 'diff' command ursusman Linux - Newbie 1 03-08-2007 04:29 AM
help on diff command anandss2004 Programming 2 11-01-2005 12:58 PM
the diff command or any other similar things murshed Linux - Newbie 4 02-12-2003 10:07 PM


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

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 Google+: linuxquestions
Open Source Consulting | Domain Registration