Solved

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

Posted on 2006-10-24
11
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

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 …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

688 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