• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

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

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
rark
Asked:
rark
  • 5
  • 3
  • 2
  • +1
2 Solutions
 
ozoCommented:
1788c1913
means change line 1788 in the first file to read as line 1913 in the second file
0
 
Duncan RoeSoftware DeveloperCommented:
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
 
rarkAuthor Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ozoCommented:
Could you post two short files along with the diff output that you don't understand?
0
 
rarkAuthor Commented:
unfortunately, when i made 2 short files, diff behaved exactly as i expected.
it returned 14a15,23.  
0
 
rarkAuthor Commented:
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
 
ravenplCommented:
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
 
Duncan RoeSoftware DeveloperCommented:
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
 
rarkAuthor Commented:
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
 
Duncan RoeSoftware DeveloperCommented:
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
 
rarkAuthor Commented:
thank you for the details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now