From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <8f07dd60b7c8ad5c85e3b6ed8ac18a37@brasstown.quanstro.net> References: <8f07dd60b7c8ad5c85e3b6ed8ac18a37@brasstown.quanstro.net> Date: Thu, 12 Mar 2015 13:07:34 -0400 Message-ID: From: minux To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=001a1147079890445705111a6ba4 Subject: Re: [9fans] fun with rc Topicbox-Message-UUID: 495aaf0c-ead9-11e9-9d60-3106f5b1d025 --001a1147079890445705111a6ba4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 =E2=88=A9 {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=E2=88=A9 {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=3D`{=E2=88=A9 $1 $2} not=E2=88=A9 c $1} > > so then > > echo 'added=3D(' `{listminus old new} ')' > echo 'deleted=3D(' `{listminus new old} ')' > --001a1147079890445705111a6ba4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Mar 12, 2015 12:52 PM, "erik quanstrom" <quanstro@quanstro.net> wrote:
> so an interesting problem i run into from time to time is separately c= omputing
> the files added to and deleted from a directory in a shell script.=C2= =A0 uniq doesn't
> work for this.=C2=A0 certainly one can loop over two lists of files an= d do this easily,
> but that seems dull and tedious.
>
> but as it turns out, one can compute the deleted and added files relat= ively
> efficiently with diff in two steps.=C2=A0 obviously uniq -d gives us t= he union, so
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 fn =E2=88=A9 {echo $$1 $$2 | sed 's/ /= \n/g' | sort | uniq -d}

Isn't this called (set) intersection?

> and uniq -u gives us not union
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 fn not=E2=88=A9 {echo $$1 $$2 | sed 's= / /\n/g' | sort | uniq -u}

this is (set) symmetric difference.

> but then we can compuete the "difference" (re= lative complement) we want
> with
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 fn listminus {c=3D`{=E2=88=A9 $1 $2} not= =E2=88=A9 c $1}
>
> so then
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo 'added=3D('=C2=A0 `{listminus= old new} ')'
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo 'deleted=3D('=C2=A0 `{listmin= us new old} ')'
>

--001a1147079890445705111a6ba4--