Solved

Why can't I get diff to work? sometimes it just outputs both files.

Posted on 2006-10-24
11
230 Views
Last Modified: 2010-04-20
I can't get diff to work consistently.
file1 has 788 lines
file2 has 913 lines.  (I think all added at the end of file 1)

when I do
$diff file1 file2 > patch
and open patch
it says
1788c1913.

which I take to mean
starting at line 1788 of file 1, you need to change 1913 lines.

sometimes diff works correctly.  And when I tried it just now on 2 short 1 line files it worked as expected.

what is going on?
0
Comment
Question by:rark
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17799585
1788c1913
means change line 1788 in the first file to read as line 1913 in the second file
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17799680
By default, diff gives you line by line changes, which is not suitable input for patch (which requires context around each change). Try using diff -c
0
 

Author Comment

by:rark
ID: 17800083
thank you both.
 i think i figure out one thing.
it's an l, not a one.
beginning at line 788 of first file, change it to line 913 of second file.  but where's the thing that says how many lines from file2 to include?  

it doesn't make sense because file 2 has 125 more lines so it should say
l788a789,913 according to how I'm reading my unix book.

it's also showign me all the lines from both files.

i tried diff -c, but it also gives me something that looks like all the lines from both.  it has 2496 lines.  i thought it'd only have about 125 lines.  [only the lines that are different]

are there other diff options i can try to just get the lines that are diff?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 84

Expert Comment

by:ozo
ID: 17800143
Could you post two short files along with the diff output that you don't understand?
0
 

Author Comment

by:rark
ID: 17800236
unfortunately, when i made 2 short files, diff behaved exactly as i expected.
it returned 14a15,23.  
0
 

Author Comment

by:rark
ID: 17800262
could it be some sort of blank space issue
maybe my developer's editor is adding blank spaces after lines
so that the 2 files look the same
but diff finds every line to be different?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 50 total points
ID: 17801425
I like the unified format it reads much easier for me, therefore try
diff -u file1 file2 > out.diff

now - what You want to do witch such diff/patch?
Note: that diff files are usually used as 'patch' command input. patch knows how to read the diff file.
Note: every line that differs is subject to diff - blank char dos vs unix end of line etc.
0
 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 200 total points
ID: 17801655
Use diff -w to ignore changes only to white space (blanks &c). patch has the -l  or  --ignore-whitespace option to do the same
0
 

Author Comment

by:rark
ID: 17804313
Thank you.  I tried to accept duncan's answer and make raven's the assisted answer, but apparently the first one chronologically is the accepted one.

my developer is on windows and I'm on linux.

when I did diff -w it solved the problem.  thank you very much.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17807210
Be careful with DOS text files (with carriage returns). Shell scripts won't work. C will compile most of the time, but you'll have trouble with continuation lines (ending backslash "\").
0
 

Author Comment

by:rark
ID: 17807306
thank you for the details.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question