[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#37753: wish for glob(7)-like matcher
From: |
Stephane Chazelas |
Subject: |
bug#37753: wish for glob(7)-like matcher |
Date: |
Wed, 13 Nov 2019 18:00:50 +0000 |
User-agent: |
NeoMutt/20171215 |
2019-10-15 12:43:14 +1100, Trent W. Buck:
[...]
> > GNU grep already has options for fixed strings (-F),
> > and BRE, ERE and PCRE. Can we have one for glob(7)?
> >
> > AFAICT nobody has asked for this before; this surprises me,
> > because it "feels" like it should be easy to implement.
> >
> > Am I wrong?
[...]
For the record, ast-open's "grep" has
-K, --ksh-regexp
ksh(1) extended file match patterns.
That's ksh93 wildcards, a superset of bash -O extglob ones
(themselves shaped after ksh88's globs) with same feature level
as regexps.
$ echo abcde | ast-grep -Ko '?c?'
bcd
You can always define a POSIX shell function like:
fnmatch() (
pattern=${1?}; shift
cat -- "$@" | while IFS= read -r line || [ -n "$line" ]; do
case $line in ($pattern) printf '%s\n' "$line"
done
)
(though that will be very slow, especially with shells that
don't have "printf" or "[" builtin; and except in zsh, it won't
work properly with input containing NUL bytes).
Note that there is some variation in wildcard syntax from one
shell to the next and one or from one fnmatch() to the next
(though they generally support the minimum POSIX set at least).
There's also the question of whether you'd want to consider \ as
an escape operator (again YMMV depending on the shell for that
fnmatch() function above).
--
Stephane
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#37753: wish for glob(7)-like matcher,
Stephane Chazelas <=