0

I want to search word line using egrep with next 1 line. I don't know the syntax for egrep on a Sun Solaris system.

4

The feature of showing additional lines before or after a grep match isn't provided in the native Solaris egrep, you would need to use GNU grep for it.

Depending on which version of Solaris you are using, this might be found in /usr/sfw/bin (Solaris 10) or /usr/gnu/bin (Solaris 11) or you may need to install it if it's not already there.

  • 1
    Later versions of Solaris 11 also provide GNU grep as /usr/bin/ggrep. – Andrew Henle Jun 25 '17 at 11:15
0

You can do it with pure perl, which is a very basic tool available in nearly every system.

#!/usr/bin/env perl

use warnings;
use strict;

my $matched = 0;
while (<>)
{
    if (/PATTERN/) { #for example /.2.*3/
        print;
        $matched = 1;
    } elsif ($matched) {
        print;
        $matched = 0;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.