LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Diff/Patch (https://www.linuxquestions.org/questions/programming-9/diff-patch-519859/)

InJesus 01-16-2007 12:30 PM

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??

wjevans_7d1@yahoo.co 01-16-2007 09:56 PM

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.

InJesus 01-16-2007 10:56 PM

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.


All times are GMT -5. The time now is 04:33 PM.