mirror of
				git://git.code.sf.net/p/zsh/code
				synced 2025-10-29 17:31:02 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			25 lines
		
	
	
	
		
			377 B
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
	
		
			377 B
		
	
	
	
		
			Text
		
	
	
	
	
	
| # 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
 | |
| }
 |