in reply to Print Lines above and below string

On the command line: grep -n5 "search_string" filename

If you want to use it in your code

my $result = `/usr/bin/grep -n5 "search_string" $file`; print $result;

Replies are listed 'Best First'.
Re^2: Print Lines above and below string
by coding_new (Sexton) on Aug 10, 2011 at 15:21 UTC

    Thanks for the input, but when I tested out that code, it simply added 5 blank lines before and after my string.

      Sorry i first thought you wanted to print empty lines. Try the "grep" command, as in my updated post