Solved

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

Posted on 2006-10-24
11
225 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Best Linux Distro for this software 10 57
LINUX, CPANEL & WHM 5 19
Sendmail STARTTLS error 37 40
Linux  Script File Attributes 5 14
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now