Ra-V
Ra-V

Reputation: 79

Unix: Egrep -a in solaris

I need the equivalent of "egrep -a " option in solaris.

Currently this option works fine in Red Hat linux, but we wanted to migrate some code in another server which is in solaris flavour.

So need to know the equivalent of "egrep -a " in solaris.

Thanks.

Upvotes: 0

Views: 1064

Answers (2)

jlliagre
jlliagre

Reputation: 30823

The -a option is a GNU grep extension which has no POSIX equivalent.

If you have a full Solaris 10 installation, you probably already have GNU grep installed in /usr/sfw/bin/ggrep (the double g is not a typo).

You can then replace the egrep -a ... occurence(s) by:

if [ -x /usr/sfw/bin/ggrep ] ; then
    EGREP_A="/usr/sfw/bin/ggrep -E"
else
    EGREP_A="egrep -a"
fi

$EGREP_A ...

If not installed, you can easily install that package SUNWggrp from you installation media (CD/DVD).

If for some reason, you can't do it, you need to provide more details about what kind of binary file it is and what pattern you are searching in it.

There are certainly other ways to overcome this issue with standard Solaris tools.

Upvotes: 1

Thomas Dickey
Thomas Dickey

Reputation: 54525

The feature requested (see manual) is documented

-a --text

Process a binary file as if it were text; this is equivalent to the --binary-files=text option.

--binary-files=type

If a file's allocation metadata, or if its data read before a line is selected for output, indicate that the file contains binary data, assume that the file is of type type. By default, type is ‘binary’, and grep normally outputs either a one-line message saying that a binary file matches, or no message if there is no match. When matching binary data, grep may treat non-text bytes as line terminators.

If type is ‘without-match’, grep assumes that a binary file does not match; this is equivalent to the -I option.

If type is ‘text’, grep processes a binary file as if it were text; this is equivalent to the -a option.

Warning: ‘--binary-files=text’ might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands.

Solaris grep (see manual) has no such feature. Third-party packages are available, e.g., CSWggrep from OpenCSW.

Upvotes: 1

Related Questions