Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
How can one compare the difference between 2 files and then redirect them to a file with the changes already applied? In other words compare the changes, make the changes and then write it to a file? thanks
You want to make this an automated process? If so: You probably cannot do that.
How would the this automated process know which of the differences are correct?
I.e: File one holds (all on 1 line) 1 2 3 4, and file two holds (again all on one line) 1 2 3 5. Is 4 correct and 5 not correct, is 5 correct and 4 incorrect or are both correct.
Hope I understood correctly and if so I hope this clears things up a bit.
$ cat file_one
this is file_one
hello world
$ cat file_two
this is file_two
hello world
$ diff -u file_one file_two | tee my.patch
--- file_one 2007-12-04 13:47:22.000000000 +0000
+++ file_two 2007-12-04 13:47:11.000000000 +0000
@@ -1,2 +1,2 @@
-this is file_one
+this is file_two
hello world
$ patch < my.patch
patching file file_one
$ cat file_one
this is file_two
hello world
In your example file_one is the file that needs to be changed, file_two is the file that holds the correct data (the 'patch'). In that case your solution works.
If, in the example the OP gave, you have two files which are different, you cannot let an automated process determine which changes are correct (see also post #2).
The OP didn't make much sense, and I took a little guess at the intention. It still doesn't make a lot of sense. Perhaps an example would help - can you provide one?
I'm still curious what the original problem was. matthewg42 and I both assumed and came up with answers that conflict. Anyway, glad to read that our input helped.
PS: Fantasy Art character??? She's alive in my reality
No, diff finds differences. Patch apples them (or ed if you tell diff to make ed-style patches).
Besides, if you have both files, and want to change file2 to be like file1, why not just copy file1 over file2?
The whole point of the diff/patch system is that you can send just the diff to someone who has a file which you have, and they can apply it without having to receive a copy of the whole new file (presumably saving bandwidth and time).
Last edited by matthewg42; 12-05-2007 at 01:41 AM.
no, what I am mean by my example is to compare two different files (file_one and file_two)for differences and remove the differences and them redirect that to a new single file. I hope I said that correctly.
no, what I am mean by my example is to compare two different files (file_one and file_two)for differences and remove the differences and them redirect that to a new single file. I hope I said that correctly.
OK, even if this is not the command you're looking for, does it essentially do the same thing (this is a test to see if my understanding of the question is correct):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.