hello,
there are many ways to skin a cat. All good suggestions, however, the file cannot be sorted. One of the files will only have appended data , meaning the data is attached to the end of the file only. The other file will have data inserts that could appear all over the file. From the example given:
file1
this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon
file2
this is mango
this is apple
this is orange
this is cherry
this is lemon
OUTPUT should be
this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon
this is cherry
this is lemon
----------------------------------
the one solution given by appending the second file appears to be what you want. That is if this example holds true. The implementation needs a little going over.
If only one file, file1 will have modified data inserts all over its contents. This can be your primary file.
The second file does not really need to start off with any content since the only data modifications to be performed are to be done on the EOF. New data appended to back of file.
If you want to keep a copy of the original file then simply have three (3) files instead of two (2)
When the event happens that you merge these files say a specific time sceduled in cron or by size or what ever it is you simply take the 3rd files contents , which are the records originally appended to the back of the secondary file. ( which now is just a copy of the original file ) a 3rd file has the new records.
then simply append file2 to file1.
--------------------
original data
----
this is mango
this is apple
this is orange
--------------------
file 1 & file 2 look like
this is mango
this is apple
this is orange
-------------------------
file 3
null
-------------------------
file1 after inserts
this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon
file2-----------------
simply a copy or dummy file showing appends
- don't really need except for archive purposes
this is mango
this is apple
this is orange
[this is cherry]
[this is lemon]
-------------------------------------
3rd / ( or 2nd ) file
this is cherry
this is lemon
OUTPUT file ( cat file2 >> file1 )
this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon
this is cherry
this is lemon