[NTLUG:Discuss] Find Files NOT containting 'string'

Lance Simmons lance at lsimmons.net
Thu Nov 6 21:48:05 CST 2003


* Stuart Johnston <sjohnston at vaultranet.com> [031106 19:00]:
> 
> I guess one way would be to grep a list of files containing the second
> string and compare it against the list of files that contain the first
> but I can't think how to easily XOR the two lists of files.

There's no doubt many better ways to do it, but this crude script seems
(after a couple of false starts) to work:

#!/bin/sh
# $1 = expression 1
# $2 = expression 2 (the unwanted one)
# $3 = list of files (such as '*', including the ''.)

grep -H $1 $3 | cut -d : -f 1 | uniq > .temp1
grep -H $2 #3 | cut -d : -f 1 | uniq > .temp2
cat .temp1 .temp2 | sort | uniq -u > .temp3
cat .temp1 .temp3 | sort | uniq -d
rm -f .temp[123]

exit 0

I hope someone has a more elegant way of doing it.

-- 
Lance Simmons



More information about the Discuss mailing list