LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   Need grep package with -A option for Solaris 10 (https://www.linuxquestions.org/questions/solaris-opensolaris-20/need-grep-package-with-a-option-for-solaris-10-a-4175474131/)

jlliagre 08-21-2013 02:31 PM

A little late but as this is Solaris 10, GNU grep was probably already installed in /usr/sfw/bin/ggrep (not a typo the first g is for GNU).

manalisharmabe 08-22-2013 04:09 AM

Thanks guys.
But one quetion , this is simple but I really never did this to be honest

What can I do to avoid using the full path

Code:

/usr/local/bin/grep
it would be nice to use this

Code:

grep -C 2 user1 /etc/passwd
instead of this.

Code:

/usr/local/bin/grep -C 2 user1 /etc/passwd
As far as I know I need to do something with "echo $PATH= " something like that but not sure what exaclty.

and yes thanks for that "-C" option, its good one.

Firerat 08-22-2013 04:24 AM

you could put /usr/local/bin/ at the beginning of PATH
Warning:
might break other things..




better solution .. try ggrep , if nothing then create a symlink in /usr/local/bin/
Code:

ln -s grep /usr/local/bin/ggrep
and make sure /usr/local/bin/ is in PATH ( towards end )

you just have to remember to use ggrep

never used solaris, but I assume you can use alias

Code:

alias grep="/usr/local/bin/grep"
depends if there is anything very special about solaris's grep, that could also cause problems
alias ggrep=.....

druuna 08-22-2013 06:14 AM

@manalisharmabe: I would first check if jlliagre solution works for you.

Assuming that ggrep isn't working for you:
If you want/need to use GNU grep inside scripts I would set a variable at the beginning of that script that points to it. From that point on you can use the variable instead of the full path:
Code:

#!/bin/bash

# assign GNU Grep to GREP
GREP="/usr/local/bin/grep"

.
.

# Grep usage
$GREP -C1 "foobar" infile

This also makes sure that aliases aren't used and possible errors in the PATH environment are circumvented (go straight to the source).

manalisharmabe 08-23-2013 02:18 AM

Quote:

Originally Posted by jlliagre (Post 5013300)
A little late but as this is Solaris 10, GNU grep was probably already installed in /usr/sfw/bin/ggrep (not a typo the first g is for GNU).

Thanks a Lot for this !!

manalisharmabe 08-23-2013 02:23 AM

Quote:

Originally Posted by Firerat (Post 5013678)
you could put /usr/local/bin/ at the beginning of PATH
Warning:
might break other things..




better solution .. try ggrep , if nothing then create a symlink in /usr/local/bin/
Code:

ln -s grep /usr/local/bin/ggrep
and make sure /usr/local/bin/ is in PATH ( towards end )

you just have to remember to use ggrep

never used solaris, but I assume you can use alias

Code:

alias grep="/usr/local/bin/grep"
depends if there is anything very special about solaris's grep, that could also cause problems
alias ggrep=.....

I will try out this on my test machine.

Thanks Guys.

Firerat 08-23-2013 02:41 AM

Quote:

Originally Posted by manalisharmabe (Post 5014290)
I will try out this on my test machine.

Thanks Guys.

When scripting, use druuna's

if it is for interactive use, then the ggrep symlink is probably best
( if ggrep doesn't already work, as pointed out by druuna )

jlliagre 08-23-2013 03:25 AM

It it isn't already, you can just put /usr/sfw/bin at the END of your PATH and if installed, ggrep will work as is.

Firerat 08-23-2013 04:02 AM

yes as jlliagre points out, look for /usr/sfw/bin

really you need to figure out what you have installed on your system(s)


All times are GMT -5. The time now is 11:01 AM.