* [9fans] fun with rc
@ 2015-03-12 16:46 erik quanstrom
2015-03-12 17:07 ` minux
2015-03-12 18:09 ` Christian Neukirchen
0 siblings, 2 replies; 5+ messages in thread
From: erik quanstrom @ 2015-03-12 16:46 UTC (permalink / raw)
To: 9fans
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}
and uniq -u gives us not union
fn not∩ {echo $$1 $$2 | sed 's/ /\n/g' | sort | uniq -u}
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} ')'
he! such fun with rc.
this is available now in 9atom.
- erik
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] fun with rc
2015-03-12 16:46 [9fans] fun with rc erik quanstrom
@ 2015-03-12 17:07 ` minux
2015-03-12 17:17 ` erik quanstrom
2015-03-12 18:09 ` Christian Neukirchen
1 sibling, 1 reply; 5+ messages in thread
From: minux @ 2015-03-12 17:07 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 1057 bytes --]
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
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} ')'
>
[-- Attachment #2: Type: text/html, Size: 1437 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] fun with rc
2015-03-12 17:07 ` minux
@ 2015-03-12 17:17 ` erik quanstrom
0 siblings, 0 replies; 5+ messages in thread
From: erik quanstrom @ 2015-03-12 17:17 UTC (permalink / raw)
To: 9fans
On Thu Mar 12 10:09:06 PDT 2015, minux.ma@gmail.com wrote:
> 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
> 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?
>
; grep `{unicode ∩} /lib/unicode
002229 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.
that sounds like a reasonable name, but not one i remembered.
- erik
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] fun with rc
2015-03-12 16:46 [9fans] fun with rc erik quanstrom
2015-03-12 17:07 ` minux
@ 2015-03-12 18:09 ` Christian Neukirchen
2015-03-12 18:31 ` erik quanstrom
1 sibling, 1 reply; 5+ messages in thread
From: Christian Neukirchen @ 2015-03-12 18:09 UTC (permalink / raw)
To: 9fans
erik quanstrom <quanstro@quanstro.net> writes:
> 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.
Isn't this a canonical use case for comm(1)?
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] fun with rc
2015-03-12 18:09 ` Christian Neukirchen
@ 2015-03-12 18:31 ` erik quanstrom
0 siblings, 0 replies; 5+ messages in thread
From: erik quanstrom @ 2015-03-12 18:31 UTC (permalink / raw)
To: 9fans
On Thu Mar 12 11:10:17 PDT 2015, chneukirchen@gmail.com wrote:
> erik quanstrom <quanstro@quanstro.net> writes:
>
> > 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.
>
> Isn't this a canonical use case for comm(1)?
yes. i hadn't thought of that. that's trivial.
- erik
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-12 18:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 16:46 [9fans] fun with rc erik quanstrom
2015-03-12 17:07 ` minux
2015-03-12 17:17 ` erik quanstrom
2015-03-12 18:09 ` Christian Neukirchen
2015-03-12 18:31 ` erik quanstrom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).