Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-10-24
11
Medium Priority
?
234 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 35

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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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 200 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 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 800 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 35

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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 …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

610 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