Merge two text files but only diferences

ammonsc
Contributor II

I am attempting to make a script that will sync Illustrator custom dictionaries. The user will run this via Self Service when they make edits or want to make sure they are current. Here is the script

#!/bin/sh

#Sync User Dictionaries for Illustrator

#Current user
user=ls -l /dev/console | cut -d " " -f 4

#Duplicate current Dictionary file

cp /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/added.txt /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/BUadded.txt

# Cat dictionary file to server stored Dictionary file

cat /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/added.txt /Volumes/Mac_Assembly/NEW_Script/MasterDictionary/addedsync.txt > /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/addededits.txt

# Copy edited file in place of old file.

cp /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/addededits.txt /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/added.txt

#Copy new dictionary back to the server

cp /Users/$user/Library/Application Support/Adobe/Linguistics/UserDictionaries/ATE User Dictionary/all/added.txt /Volumes/Mac_Assembly/NEW_Script/MasterDictionary/addedsync.txt

This works but the file just copies the same thing over and over again. I need it to just add the latest additions to the text document.

1 ACCEPTED SOLUTION

thoule
Valued Contributor II

I don't know this dictionary. Does line order matter? If not, you could just do a sort command to pull out duplicate lines. sort bigfile.txt -u -o lessbigfile.txt
the 'u' means unique lines only. -o means output file.

If sort order does matter, you'll have to go through each line in the script, grep for it, then output if necessary. -t-

View solution in original post

2 REPLIES 2

thoule
Valued Contributor II

I don't know this dictionary. Does line order matter? If not, you could just do a sort command to pull out duplicate lines. sort bigfile.txt -u -o lessbigfile.txt
the 'u' means unique lines only. -o means output file.

If sort order does matter, you'll have to go through each line in the script, grep for it, then output if necessary. -t-

ammonsc
Contributor II

using

sort -uf worked perfectly

Thanks!