How to find egrep version on Solaris 10

Hi,
How can I find the egrep version installed on Solaris 10 as I don't see any egrep --version option.Also wanted to know which version would support option of -A (eg. egrep -A NUM PATTERN FILE )
Print NUM lines of trailing context after matching lines.

Thanks & Regards,
Kiran.

i can only help answer the first question ...

  1. grep out /usr/bin/egrep from /var/sadm/install/contents

  2. the package that installed egrep on my box is SUNWcsu --- verify on your box by looking at the last column on the output of grep

  3. pkginfo -l SUNWcsu | grep "VERS"

Hi ,
Just Ice,Thanks for your reply.I found my egrep version to be VERSION:11.10.0 on my Solaris 10 Box.But would anyone help me if I can have -A option with egrep coz this option is supported on linux egrep (GNU grep) version 2.5.1 or is there any other option on Solaris that would give me similar results.

Thanks & Regards,
Kiran.

-bash-3.00$ ./kiran.sh ab 0 0 ./testfile
abc
abc
abc
-bash-3.00$ ./kiran.sh ab 0 2 ./testfile
abc
1
2
abc
1
2
abc
.
!
-bash-3.00$
-bash-3.00$ cat ./kiran.sh
#!/bin/ksh
# no -C option to grep? no fear...
# usage:
#   scriptname "searchterm" lines_before lines_after inputfile

matchstring="$1"
lines_before="$2"
lines_after="$3"
matchfile="$4"

matches=`echo "${line}" | egrep -n "${matchstring}" ${matchfile}`
if [ "$?" -ne "0" ]; then
   echo "No match" >&2
   exit 1
fi
echo "${matches} " | while read line; do
   lineno=`echo "${line}" | cut -d: -f1`
   match=`echo "${line}" | cut -d: -f2`
#  echo "Match found - line ${lineno} - ${match}"
   minline=$(( lineno - ${lines_before} ))
   [[ "$(( lineno - ${lines_before} ))" -lt 1 ]] && minline=1
   [[ "${lines_before}" -gt "0" ]] && \
   sed -n "$minline,$(( lineno - 1 ))p" ${matchfile}
   sed -n "$lineno p" ${matchfile}
   [[ "${lines_after}" -gt "0" ]] && \
   sed -n "$(( lineno + 1 )),$(( lineno + ${lines_after} ))p" ${matchfile}
done

exit 0

So for your requirements

scriptname "searchterm" 0 <trailing_lines> filename

Cheers
ZB

Hi,

I think this question came in a recent post .... You can try out some solutions given in that post :

Sabari Nath S

Hi Zazzybob,
Thanks for script :slight_smile: Its cool!!!
But would still like to know if Solaris does NOT support this option for egrep as in linux.

Cheers,
Kiran.

Solaris 10 and below do not support it - load GNU grep on your system instead.
Where to get egrep