From 2d8c55c30858c190342f84b8e665e41b7ba44008 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 19 Oct 2020 22:48:42 +0100 Subject: [PATCH] pcat: change -v to allow coexistance of `grep -v` and regular `grep -e` calls in the pipeline Signed-off-by: Alejandro Mery --- files/bin/pcat | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/files/bin/pcat b/files/bin/pcat index 31e2e86..a806aaa 100755 --- a/files/bin/pcat +++ b/files/bin/pcat @@ -9,6 +9,7 @@ UNTIL= SED_ARGS= GREP_ARGS= +GREPV_ARGS= # bin helpers # @@ -97,10 +98,6 @@ while [ $# -gt 0 ]; do shift ;; - # grep -i - -i) - GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1" - ;; # simple grep options with arguments -C|-A|-B) GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1 $2" @@ -120,9 +117,13 @@ while [ $# -gt 0 ]; do GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }-e '$2'" shift ;; - - # simple grep options without arguments + # -v is `grep -v e` -v) + GREPV_ARGS="${GREPV_ARGS:+$GREPV_ARGS }-e '$2'" + shift + ;; + # simple grep options without arguments + -i) GREP_ARGS="${GREP_ARGS:+$GREP_ARGS }$1" ;; @@ -148,6 +149,11 @@ done PIPELINE= +# GREP -v FILTER +if [ -n "${GREPV_ARGS:-}" ]; then + PIPELINE="${PIPELINE:+$PIPELINE | }$GREP -a -v $GREPV_ARGS" +fi + # FROM/UNTIL FILTER if [ -n "${FROM:-}${UNTIL:-}" ]; then PIPELINE="${PIPELINE:+$PIPELINE | }$SED"