Re: Off-topic: filtering stream of pathnames for glob'd exclusions

2024-04-22 Thread Seth David Schoen
Philip Prindeville writes:

> Hi,
> 
> Somewhat off-topic post but this is on a system that has Busybox installed so 
> I can't use features that other shells might provide.
> 
> I have a stream generated by "find" of pathnames, and I want to delete 
> (filter out) certain paths based on the contents of a file that holds 
> exclusions.

If you can modify the find command itself, you could add a "-not -path"
clause with a glob pattern.

For example,

find / -not -path '*e*'

finds all paths on the system that don't contain the letter e.  If there
aren't too many such lines, you could make a "-not -path" clause for each of
them.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


RE: Off-topic: filtering stream of pathnames for glob'd exclusions

2024-04-22 Thread David Laight
From: Philip Prindeville
> Sent: 22 April 2024 17:16
> Somewhat off-topic post but this is on a system that has Busybox installed so 
> I can't use features
> that other shells might provide.
> 
> I have a stream generated by "find" of pathnames, and I want to delete 
> (filter out) certain paths
> based on the contents of a file that holds exclusions.
> 
> Anyone know an easy way to do this?  Something like "... | grep -v -f 
> exclusions.txt" if grep worked
> with globs instead of patterns...

A shell 'case' statement will do filename 'glob' matching.
so something like:
find ... | while read path; do
case $path in
(exclusion_1 | exclusion_2 ...) ;;
(*) echo $path;;
esac
done
might work (modulo some extra quoting - probably ' around the patterns).
That does require a pre-process of your exclusions.txt file.
With a bit of care you can use the shells eval on the entire case statement
to do that in the script itself.
If you use eval make sure you quote everything except the variables you
want expanded on the first pass.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox