Browse Source

pcat: change -v to allow coexistance of `grep -v` and regular `grep -e` calls in the pipeline

Signed-off-by: Alejandro Mery <amery@geeks.cl>
master
Alejandro Mery 4 years ago
parent
commit
2d8c55c308
1 changed files with 12 additions and 6 deletions
  1. +12
    -6
      files/bin/pcat

+ 12
- 6
files/bin/pcat

@ -9,6 +9,7 @@ UNTIL=
SED_ARGS= SED_ARGS=
GREP_ARGS= GREP_ARGS=
GREPV_ARGS=
# bin helpers # bin helpers
# #
@ -97,10 +98,6 @@ while [ $# -gt 0 ]; do
shift shift
;; ;;
# grep -i
-i)
GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1"
;;
# simple grep options with arguments # simple grep options with arguments
-C|-A|-B) -C|-A|-B)
GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1 $2" GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1 $2"
@ -120,9 +117,13 @@ while [ $# -gt 0 ]; do
GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }-e '$2'" GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }-e '$2'"
shift shift
;; ;;
# simple grep options without arguments
# -v is `grep -v e`
-v) -v)
GREPV_ARGS="${GREPV_ARGS:+$GREPV_ARGS }-e '$2'"
shift
;;
# simple grep options without arguments
-i)
GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1" GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1"
;; ;;
@ -148,6 +149,11 @@ done
PIPELINE= PIPELINE=
# GREP -v FILTER
if [ -n "${GREPV_ARGS:-}" ]; then
PIPELINE="${PIPELINE:+$PIPELINE | }$GREP -a -v $GREPV_ARGS"
fi
# FROM/UNTIL FILTER # FROM/UNTIL FILTER
if [ -n "${FROM:-}${UNTIL:-}" ]; then if [ -n "${FROM:-}${UNTIL:-}" ]; then
PIPELINE="${PIPELINE:+$PIPELINE | }$SED" PIPELINE="${PIPELINE:+$PIPELINE | }$SED"

Loading…
Cancel
Save