File: zpgrep

package info (click to toggle)
zsh 4.3.6-6
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 14,436 kB
  • ctags: 7,192
  • sloc: ansic: 87,447; sh: 5,590; makefile: 836; perl: 619; awk: 381; sed: 16
file content (25 lines) | stat: -rw-r--r-- 377 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
}