[Courses][Linux comands] Finding things with locate, find, and grep

Dan Richter daniel.richter at wimba.com
Thu Feb 19 11:17:34 EST 2004


> I'd like to grep a file for a generic error message,
> and have the result return a line number where I can quickly get to via
> vi or some other editor to look as the lines just above to see what
> might have caused the error.

In addition to -n (line number), you can use -<number>, which causes 
grep to output <number> lines before and after the match:

    grep -n -3 'Free Software Foundation' GPL.txt

GNU grep allows you to use -A <num> and -B <num> to specify 
(respectively) the number of lines before and after the match to output, 
but I suspect that this behavior is less portable.

-- 
    Any given program, when running, is obsolete.
           - From "Murphy's Law on Technology",
             http://home.swipnet.se/~w-10724/Murphytec.html



More information about the Courses mailing list