Ok, I have two related lists on my linux box in text files:
/tmp/oldList
/tmp/newList
I need to compare these lists to see what lines got added and what lines got removed. I then need to loop over these lines and perform actions on them based on whether they were added or removed.
How do I do this in bash?
Use the
comm(1)command to compare the two files. They both need to be sorted, which you can do beforehand if they are large, or you can do it inline with bash process substitution.commcan take a combination of the flags-1,-2and-3indicating which file to suppress lines from (unique to file 1, unique to file 2 or common to both).To get the lines only in the old file:
To get the lines only in the new file:
You can feed that into a
while readloop to process each line:and similarly for the new lines.