mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 16:50:58 +01:00
15211: zsh/pcre module
This commit is contained in:
parent
0f960cc8ca
commit
bff61cf9e1
6 changed files with 200 additions and 2 deletions
25
Functions/Example/zpgrep
Normal file
25
Functions/Example/zpgrep
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Usage: zpgrep <perl5-compatible regex> <file1> <file2> ... <fileN>
|
||||
#
|
||||
|
||||
zpgrep() {
|
||||
local file pattern
|
||||
|
||||
pattern=$1
|
||||
shift
|
||||
|
||||
if ((! ARGC)) then
|
||||
set -- -
|
||||
fi
|
||||
|
||||
pcre_compile $pattern
|
||||
pcre_study
|
||||
|
||||
for file
|
||||
do
|
||||
if [[ "$file" == - ]] then
|
||||
while read -u0 buf; do pcre_match $buf && print $buf; done
|
||||
else
|
||||
while read -u0 buf; do pcre_match $buf && print $buf; done < "$file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue