January 2004
Intermediate to advanced
368 pages
7h 25m
English
Some versions of grep offer a remarkable variety of capabilities, including the particularly useful ability to show the context (a line or two above and below) of a matching line in the file. Additionally, some rare versions of grep can highlight the region in the line (for simple patterns, at least) that matches the specified pattern.
Both of these useful features can be emulated in a shell script, so that even users on older commercial Unixes with relatively primitive grep commands can enjoy them. This script also borrows from the ANSI color script, Script #11.
#!/bin/sh # cgrep - grep with context display and highlighted pattern matches. context=0 esc="^[" bOn="${esc}[1m" bOff="${esc}[22m" sedscript="/tmp/cgrep.sed.$$" ...Read now
Unlock full access