Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

more file filtering (e::), stest, perl (Re: A question about filename generate)



hello,

On Mon, Jul 28, 2025 at 09:25:26AM -0500, Perry Smith wrote:
> I’m assuming that pat of the expression ^pat is a glob pattern.  And
> x^y: my guess is that both x and y are glob patterns.

if you read the 'FILENAME GENERATION' section from zshexpn, you'll see
that ^x exists, x~y exists but there is no thing such x^y.

don't hesitate to ask for more help if you want some. In the meanwhile,
maybe you should be aware of the (e::) modifier which can run arbritrary
test for each matched files

files=( bob bill bibi bobybibi )
for REPLY ($files) {
	(( $(<<< $REPLY tr -dc b | wc -c ) < 3 )) && echo $REPLY
}

touch $files

print -l *(e:'(($(<<< $REPLY tr -dc b | wc -c ) < 3 ))':)

for readability sake, it's better declare a function

no_more_than() ((
	$( <<< ${3:-$REPLY} |
	tr -dc ${2?undesirable caracter} |
	wc -c ) < ${1?limit} ))

no_more_than 3 b bobybibi || echo bad bad boy

ls *(e:'no_more_than 3 b':)

be aware that the filter is executed for *each* files so
if you have many files, a better solution is to rely on a command
that stream a list of files to a filter.

you can use stest (a tool from suckless.org)

ls | stest -f # only files

but when the thing is harder, perl is your swiss chainsaw!

ls | perl -lnE 'print unless -f && y/b// > 3'

# -f test if the line contains a filename
# y/// is like tr -d b but it returns the number of substitutions

regards

-- 
Marc Chantreux
Pôle CESAR (Calcul et services avancés à la recherche)
Université de Strasbourg
14 rue René Descartes,
BP 80010, 67084 STRASBOURG CEDEX
03.68.85.60.79

Attachment: signature.asc
Description: PGP signature



Messages sorted by: Reverse Date, Date, Thread, Author