Reputation: 195
Both files has lines of string and numeric data minimum of 2000 lines.
How to add non duplicate data from file2.txt
to file1.txt
.
Basically file2 has the new data lines but we also want to ensure we are not adding duplicate lines to file1.txt.
File1.txt
> this is the main data file File2.txt
> this file has the new data we want to add to file1thanks,
Upvotes: 2
Views: 3012
Reputation: 157967
You can use grep
, like this:
# grep those lines from file2 which are not in file1
grep -vFf file1 file2 > new_file2
# append the results to file1
cat new_file2 >> file1
Upvotes: 1
Reputation: 70460
Another option if the file is sorted, just to have some choice (and I like comm
:) )
comm --check-order --output-delimiter='' -13 File1.txt File2.txt >> File1.txt
Upvotes: 2
Reputation: 780974
Sort the two files together with the -u
option to remove duplicates.
sort -u File1.txt File2.txt > NewFile.txt && mv NewFile.txt File1.txt
Upvotes: 4