diff options
| author | Clint Adams <clint@users.sourceforge.net> | 2001-07-02 19:39:34 +0000 |
|---|---|---|
| committer | Clint Adams <clint@users.sourceforge.net> | 2001-07-02 19:39:34 +0000 |
| commit | bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a (patch) | |
| tree | f4b8e78b61816b2487da262a6631c62358888f7f /Functions/Example | |
| parent | fix IRIX 5.3 specific compilation problems and some error messages (15204) (diff) | |
| download | zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.tar zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.tar.gz zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.tar.bz2 zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.tar.lz zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.tar.xz zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.tar.zst zsh-bff61cf9e1b2fd17eb971c1e5253f4d84eaedd3a.zip | |
15211: zsh/pcre module
Diffstat (limited to 'Functions/Example')
| -rw-r--r-- | Functions/Example/zpgrep | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Functions/Example/zpgrep b/Functions/Example/zpgrep new file mode 100644 index 000000000..8b1edaa1c --- /dev/null +++ b/Functions/Example/zpgrep @@ -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 +} |
