You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
894 B

# Perl grep since 'grep -P' is terrible.
local usage pattern modifiers
usage="$(
cat <<EOF
usage: $0 [-option ...] [--] pattern [file ...]
options:
-i ignore case
-m ^ and $ match the start and the end of a line
-s . matches newline
-x ignore whitespace and comments
EOF
)"
while getopts ':igmxe::' opt; do
case "$opt" in
(i) modifiers="${modifiers}i" ;;
(m) modifiers="${modifiers}m" ;;
(x) modifiers="${modifiers}x" ;;
(e) modifiers="${modifiers}e" ;;
(:)
print "$0: option requires an argument: $OPTARG" >&2
print "$usage" >&2
return 1
;;
([?])
print "$0: unknown option: $OPTARG" >&2
print "$usage" >&2
return 1
;;
esac
done
shift $(( $OPTIND - 1 ))
if (( $# < 1 )); then
print "$usage" >&2
return 1
fi
pattern="$1"
shift
perl -n -l -e "print if m/${pattern//\//\\/}/${modifiers}" "$@"