GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — shell-script/036-cgrep.sh at master · srinivart/shell-script Expand file tree/ Copy path036-cgrep.shMore file actions executable file ·68 lines (55 loc) · 1.33 KB / Copy path036-cgrep.shFile metadata and controlsexecutable file ·68 lines (55 loc) · 1.33 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 #!/bin/sh # cgrep - grep with context display and highlighted pattern matches context=0 esc="" bOn="${esc}[1m" bOff="${esc}[22m" sedscript="/tmp/cgrep.sed.$$" tempout="/tmp/cgrep.$$" showMatches() { matches=0 echo "s/$pattern/${bOn}$pattern${bOff}/g" > $sedscript for lineno in $(grep -n "$pattern" $1 | cut -d: -f1) do if [ $context -gt 0 ] ; then prev="$(( $lineno - $context ))" if [ "$(echo $prev | cut -c1)" = "-" ] ; then prev="0" fi next="$(( $lineno + $context ))" if [ $matches -gt 0 ] ; then echo "${prev}i\\" >> $sedscript echo "----" >> $sedscript fi echo "${prev},${next}p" >> $sedscript else echo "${lineno}p" >> $sedscript fi matches="$(( $matches + 1 ))" done if [ $matches -gt 0 ] ; then sed -n -f $sedscript $1 | uniq | more fi } trap "/bin/rm -f $tempout $sedscript" EXIT if [ -z "$1" ] ; then echo "Usage: $0 [-c X] pattern {filename}" >&2; exit 0 fi if [ "$1" = "-c" ] ; then context="$2" shift; shift elif [ "$(echo $1|cut -c1-2)" = "-c" ] ; then context="$(echo $1 | cut -c3-)" shift fi pattern="$1"; shift if [ $# -gt 0 ] ; then for filename ; do echo "----- $filename -----" showMatches $filename done else cat - > $tempout # save stream to a temp file showMatches $tempout fi exit 0 |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |