Re: [vox-tech] regex expansion tool, anyone?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox-tech] regex expansion tool, anyone?
- Subject: Re: [vox-tech] regex expansion tool, anyone?
- From: Chuck Polisher <cpolish@MAPSns.net>
- Date: Tue, 28 Nov 2000 19:51:33 -0800
- References: 20001127132311.A16553@houseag.com
> Does anyone know of a tool that will show all possible matches to character
> class regexes? E.g., [a-f][RvP][3fk].
#!/bin/bash
# showmatch: show strings that match regular expresion
# usage: showmatch [regular expression] [file]
pat=$1; shift
gawk 'match($0,pat) > 0 {
s = substr($0,1,RSTART-1)
m = substr($0,1,RLENGTH)
gsub (/[^\b- ]/, " ", s)
gsub (/./, "^", m)
printf "%s\n%s%s\n", $0, s, m
}' pat="$pat" $*
source: Unix Power Tools, Peek, 2nd ed.
|