On Mar 12, 2015 12:52 PM, "erik quanstrom" wrote: > so an interesting problem i run into from time to time is separately computing > the files added to and deleted from a directory in a shell script. uniq doesn't > work for this. certainly one can loop over two lists of files and do this easily, > but that seems dull and tedious. > > but as it turns out, one can compute the deleted and added files relatively > efficiently with diff in two steps. obviously uniq -d gives us the union, so > > fn ∩ {echo $$1 $$2 | sed 's/ /\n/g' | sort | uniq -d} Isn't this called (set) intersection? > and uniq -u gives us not union > > fn not∩ {echo $$1 $$2 | sed 's/ /\n/g' | sort | uniq -u} this is (set) symmetric difference. > but then we can compuete the "difference" (relative complement) we want > with > > fn listminus {c=`{∩ $1 $2} not∩ c $1} > > so then > > echo 'added=(' `{listminus old new} ')' > echo 'deleted=(' `{listminus new old} ')' >