comm '! sort file1' '! sort file2'

Griff Smith ggs at ulysses.UUCP
Thu Sep 25 03:09:18 AEST 1986


> I regularly want to run "comm" on a pair of unsorted files.  So I ended up
> writing a shell script to do the job, the guts of which (simplified for the
> purposes of this article) is:
> 
> 	tmp=/tmp/\#scomm.$$
> 	sort "$1" > $tmp
> 	sort "$2" | comm $tmp -
> 	rm $tmp
> 
> All fine and dandy.  But then I got to thinking. . .that what I'd *really*
> like to be able to do is use a command like
> 
> 	comm '! sort file1' '! sort file2'
> 
> (where the space after the '!' should be your clue that I use csh) and have
> comm do the dirty work.
> 
> And then I got to thinking. . .that if fopen turned
> 	fopen("!whatever", "r")
> calls into
> 	popen("whatever", "r")
> calls (with other changes as necessary), then what I'd like to see happen
> with the "comm" command would happen generally.
> 
> Comments?
> --
> UNIX is a registered trademark of AT&T.
> --
> 	UUCP: ..decvax!seismo!elsie!ado   ARPA: elsie!ado at seismo.ARPA
> 	DEC, VAX, Elsie & Ado are Digital, Borden & Ampex trademarks.

And then I get to re-build all the commands with the new library.
This is exactly what the shell was designed to avoid!  Such features
belong in the shell!  The Korn shell supports the syntax

	comm <(sort file1) <(sort file2)

The expression "<(sort file1)" turns into /dev/fd/n, where "n" is
the file descriptor number for the pipe.  True, this only works
on V8 and on systems that have had the /dev/std{in,out,err} feature
added to the kernel, but it is a much cleaner solution.  Then
I get to worry about

	diff <(sort file1) <(sort file2)

which fails because diff can't seek on the pipe.
-- 

Griff Smith	AT&T (Bell Laboratories), Murray Hill
Phone:		(201) 582-7736
UUCP:		{allegra|ihnp4}!ulysses!ggs
Internet:	ggs at ulysses.uucp



More information about the Comp.unix.wizards mailing list