LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Question on diff command (http://www.linuxquestions.org/questions/programming-9/question-on-diff-command-632863/)

just.srad 04-03-2008 10:40 PM

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

gilead 04-03-2008 11:31 PM

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?

Dan04 04-03-2008 11:35 PM

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.

gnashley 04-04-2008 05:06 AM

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.

just.srad 04-05-2008 04:01 AM

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. =)


All times are GMT -5. The time now is 09:28 AM.