LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   append files (https://www.linuxquestions.org/questions/linux-general-1/append-files-379833/)

Paul_R 11-04-2005 02:47 AM

merge two files
 
Hi Guys,

Im trying to create a backup mailserver for some cpanel servers.

This involves a file on backup server (/etc/secondarymx) containing the contents of a file (/etc/localdomains) from each other server wishing to use it.

I can copy the "localdomains" file over to the backup server which is fine but how do I merge the file contents to the "secondarymx" file without creating duplicate data.

The files are just domain lists with line breaks i.e.
domain1
domain2
domain3...

Thanks,

Paul

ashamril 11-04-2005 03:37 AM

# cat localdomains >> secondarymx

Paul_R 11-04-2005 03:46 AM

Quote:

Originally posted by ashamril
# cat localdomains >> secondarymx
Sorry, I meant merge not append, I have edited my post.

ns_sanish 11-04-2005 05:19 AM

after appending do a "sort -u" on the file to remove dups

Paul_R 11-04-2005 05:46 AM

Quote:

Originally posted by ns_sanish
after appending do a "sort -u" on the file to remove dups
Hi,

Thanks for your help :)

I ran "sort -u data3" data3 being the final output file, it sorts it on the screen however does not write this to the file so data3 remains with duplicates. :confused:

ns_sanish 11-04-2005 05:56 AM

ofcourse u will have to redirect the output of sort to another file and then overwrite the original with the new one.

sort -u secondarymx > secondarymx.tmp
mv secondarymx.tmp secondarymx

Paul_R 11-04-2005 06:15 AM

Quote:

Originally posted by ns_sanish
ofcourse u will have to redirect the output of sort to another file and then overwrite the original with the new one.

sort -u secondarymx > secondarymx.tmp
mv secondarymx.tmp secondarymx

Thank you very much :)


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