#!/bin/bash # Troels Arvin , $Date: 2010-09-07 13:01:26 +0200 (Tue, 07 Sep 2010) $. # Script to compensate for Linux' grep not having the equivalent # of AIX' "grep -p" (paragraph grep). # Public domain script. Use it on your own risk. # Latest version at http://troels.arvin.dk/code/shell/pargrep/ thisscript=`basename $0` negated='' insensitive='' needle='' err () { msg="$1" echo "error while running $thisscript: $msg" >&2 exit 1 } usage () { echo "Usage:" echo "$thisscript [-i] [-v] " echo echo " -i: match case insentitively" echo " -v: negate matching" echo echo "Searches standard input for , paragraph per paragraph," echo "somewhat alike AIX' 'grep -p'." echo "Perl is used behind the back, so regex style i perl-regex." exit 0 } [ "$1" == '-h' -o "$1" == '--help' ] && usage while getopts ":vi" options; do case "$options" in v) negated='not' ;; i) insensitive='i' ;; *) err "unknown argument $OPTARG" ;; esac done shift $(($OPTIND - 1)) needle="$1" [ -z "$needle" ] && err "no search string indicated" perl -ne "BEGIN {\$/ = \"\n\n\"} print if $negated /$needle/${insensitive}"