Given a filename like 'prefix.extension', I would like to find all files of the pattern prefix\\.\\d\\d\\.extension
. Given that 'prefix' or 'extension' could contain literal strings like .*
, \\n
and the like, the only way I can think of finding this properly is to escape all characters in 'prefix' and 'extension', placing them before and after \\.\\d\\d\\.
, and egrep
-ing it. Is there a more elegant way of doing this and/or some simple way to escape all special characters for egrep
in a Bash script?
Note that putting a backslash in front of every character will change the semantics of some, like \\w
.
原来grep --perl-regexp
与\\Q
和\\E
符合我的要求:
ls -1N -- "${source_dir}" | grep -P "^\Q${source_base}.\E\d\{${fragment_digits}\}\Q.${source_extensions}\E\$"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.