LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2007, 12:30 PM   #1
InJesus
Member
 
Registered: Oct 2005
Location: MN
Distribution: Slack, Slamd64
Posts: 33

Rep: Reputation: 15
Diff/Patch


I've got two files an old and a new file

File1:
Code:
1,"red"
2,"green"
3,"blue"
File2:
Code:
1,"red"
2,"green"
3,"blue"
4,"purple"
5,"teal"
now doing
Code:
diff file1 file2 > file.diff
touch txt.file
patch -p0 < file.diff txt.file
works great, I get the differences only in a nice text format.
However if I remove say line 3 from the second file, patch will not just give me all the differences of the File2. it will say Hunk 2 has failed and creates a rej file. Then the output from the patch will only have the line that was removed in it. But if I just change line 3 from blue to yellow, it's fine. anyone run into this problem, am i doing it all wrong from the start??
 
Old 01-16-2007, 09:56 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
You're trying to use patch for something for which it was not intended.

The purpose of patch is to take as input two files:

1. the "older" version of a source file
2. the differences

and produce the second file.

For example, if you have file1 and file2, and they're large, but the differences between them are small, and you have clients who all have file1, you can send them the differences betweeen file1 and file2 (instead of all of file2) and they can create file2 on their own, using patch.

file.diff, from my point of view, is already in a "nice text" format. But if file.diff is not in a sufficiently "nice text format" for you, that's fine. So how would it look differently to suit your needs? Maybe we can help you with that.
 
Old 01-16-2007, 10:56 PM   #3
InJesus
Member
 
Registered: Oct 2005
Location: MN
Distribution: Slack, Slamd64
Posts: 33

Original Poster
Rep: Reputation: 15
thanks for the reply

Thanks for your help, I figured as much. I was just wondering if there was a way to use patch to do what I wanted. For those who in the future might look at this I've turned to sed.

try this command(to isolate the files to only the differences):
Code:
sed -n -i '/\(^\)>/p' file.diff
then another sed to get rid of the ">" and your good to go.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
patch -p1 x.diff but no patch command!? pyenos Linux - Hardware 1 03-04-2005 03:10 PM
What's the difference between .diff and .patch? nidua18 Linux - Software 0 10-15-2003 12:25 AM
I have a patch (diff file). What now? Gurduloo Linux - Newbie 2 05-27-2003 02:20 PM
diff-patch mtb Linux - Software 1 03-23-2003 01:49 PM
trying to patch i810_audio diff file McQuaid Linux - General 1 11-28-2002 05:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration