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

Marc Chantreux <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <aIeUdKJOEXBEYxai@prometheus>
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
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQQrhynLytp14smlCwy+er2aYc+1WAUCaIeUbwAKCRC+er2aYc+1
WJ8AAQDlAvhI+zkbcuEt4nobdLREVSa0FO/dGmHf+4ZnBz1DigEA94mi0PiCsQEP
b6/slF0jROI6zlglI6c2qXFJDrLCGgs=
=S8pw
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.