Fixed Perl find/substitute options, added inverse.
This commit is contained in:
parent
f77e2c8e05
commit
e1a71a84b1
|
@ -5,6 +5,7 @@ _arguments \
|
||||||
'-i[ignore case]' \
|
'-i[ignore case]' \
|
||||||
'-m[^ and $ match the start and the end of a line]' \
|
'-m[^ and $ match the start and the end of a line]' \
|
||||||
'-s[. matches newline]' \
|
'-s[. matches newline]' \
|
||||||
|
'-v[invert match]' \
|
||||||
'-x[ignore whitespace and comments]' \
|
'-x[ignore whitespace and comments]' \
|
||||||
'1::pattern:' \
|
'1::pattern:' \
|
||||||
'2::files:_files' && return 0
|
'2::files:_files' && return 0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Perl grep since 'grep -P' is terrible.
|
# Perl Grep
|
||||||
|
|
||||||
local usage pattern modifiers
|
local usage pattern modifiers invert
|
||||||
|
|
||||||
usage="$(
|
usage="$(
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -10,16 +10,18 @@ options:
|
||||||
-i ignore case
|
-i ignore case
|
||||||
-m ^ and $ match the start and the end of a line
|
-m ^ and $ match the start and the end of a line
|
||||||
-s . matches newline
|
-s . matches newline
|
||||||
|
-v invert match
|
||||||
-x ignore whitespace and comments
|
-x ignore whitespace and comments
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
|
|
||||||
while getopts ':igmxe::' opt; do
|
while getopts ':imsxv' opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
(i) modifiers="${modifiers}i" ;;
|
(i) modifiers="${modifiers}i" ;;
|
||||||
(m) modifiers="${modifiers}m" ;;
|
(m) modifiers="${modifiers}m" ;;
|
||||||
|
(s) modifiers="${modifiers}s" ;;
|
||||||
(x) modifiers="${modifiers}x" ;;
|
(x) modifiers="${modifiers}x" ;;
|
||||||
(e) modifiers="${modifiers}e" ;;
|
(v) invert="yes" ;;
|
||||||
(:)
|
(:)
|
||||||
print "$0: option requires an argument: $OPTARG" >&2
|
print "$0: option requires an argument: $OPTARG" >&2
|
||||||
print "$usage" >&2
|
print "$usage" >&2
|
||||||
|
@ -42,5 +44,5 @@ fi
|
||||||
pattern="$1"
|
pattern="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
perl -n -l -e "print if m/${pattern//\//\\/}/${modifiers}" "$@"
|
perl -n -l -e "print if ${invert:+not} m/${pattern//\//\\/}/${modifiers}" "$@"
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,13 @@ options:
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
|
|
||||||
while getopts ':igmxe::' opt; do
|
while getopts ':gimsx' opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
(i) modifiers="${modifiers}i" ;;
|
|
||||||
(g) modifiers="${modifiers}g" ;;
|
(g) modifiers="${modifiers}g" ;;
|
||||||
|
(i) modifiers="${modifiers}i" ;;
|
||||||
(m) modifiers="${modifiers}m" ;;
|
(m) modifiers="${modifiers}m" ;;
|
||||||
|
(s) modifiers="${sodifiers}s" ;;
|
||||||
(x) modifiers="${modifiers}x" ;;
|
(x) modifiers="${modifiers}x" ;;
|
||||||
(e) modifiers="${modifiers}e" ;;
|
|
||||||
(:)
|
(:)
|
||||||
print "$0: option requires an argument: $OPTARG" >&2
|
print "$0: option requires an argument: $OPTARG" >&2
|
||||||
print "$usage" >&2
|
print "$usage" >&2
|
||||||
|
@ -46,3 +46,4 @@ replacement="$2"
|
||||||
repeat 2 shift
|
repeat 2 shift
|
||||||
|
|
||||||
perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@"
|
perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue