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/)

manalisharmabe 08-21-2013 06:44 AM

Need grep package with -A option for Solaris 10
 
Need grep package with -A option for Solaris 10

--------------------------------------------------------------------------------

Hi Guys,

I need grep package with -A option for Solaris 10,
Where can I download this from,

Please advise.

druuna 08-21-2013 06:51 AM

GNU Grep for Solaris is available here: Sunfreeware

manalisharmabe 08-21-2013 06:56 AM

yes,i have downloaded from it. but it has no A option.
please suggest.

Firerat 08-21-2013 07:03 AM

try full path

/usr/gnu/bin/grep

druuna 08-21-2013 07:03 AM

Are you using the full path to gnu grep? Its been a while, but I do believe gnu grep is installed in /usr/local/bin.

manalisharmabe 08-21-2013 07:13 AM

look i wan to try this
http://stackoverflow.com/questions/1...-matching-line

I should be abale to print line above and below of searched word say "failed"

now tell me how to do the same thing in Solaris 10

Code:

[raju@100 ~]$ grep -A 1 -B 1 oprofile  /etc/passwd
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
oprofile:x:16:16:Special user account to be used by OProfile:/home/oprofile:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
[raju@100 ~]$

above is what we do in linux, so how to do this in Solaris

druuna 08-21-2013 07:17 AM

Quote:

Originally Posted by manalisharmabe (Post 5013064)
look i wan to try this
http://stackoverflow.com/questions/1...-matching-line

I should be abale to print line above and below of searched word say "failed"

We know what the -A and -B switch do.

Please answer the question asked by Firerat and me.

It would also be nice if you posted the command you are trying to use.

Quote:

now tell me how to do the same thing in Solaris 10
Play nice! We are trying to help but we cannot if you don't answer our questions!

manalisharmabe 08-21-2013 07:20 AM

I dont mean rude . please!

manalisharmabe 08-21-2013 07:21 AM

I want to do the same thing as posted above to search some logfile and their above below lines around particular search word in Solaris 10

Firerat 08-21-2013 07:22 AM

see posts #4 and #5
I've never used solaris , so I don't know which is 'true'
only going off what I have seen posted here on LQ in the past

manalisharmabe 08-21-2013 07:23 AM

Code:

-bash-3.2$ which grep
/usr/bin/grep
-bash-3.2$ cd /usr/local/bin
-bash-3.2$ ls grep
grep
-bash-3.2$

-
I have this grep located at system.

druuna 08-21-2013 07:25 AM

To make sure you are using the GNU version:
Code:

/usr/local/bin/grep --version
GNU grep <version number>

...
...

If the above is the case you can use:
Code:

/usr/local/bin/grep -A .......

manalisharmabe 08-21-2013 07:27 AM

Code:

-bash-3.2$ /usr/local/bin/grep --version
/usr/local/bin/grep (GNU grep) 2.14
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
-bash-3.2$

this what i have

manalisharmabe 08-21-2013 07:33 AM

Code:

-bash-3.2$ /usr/local/bin/grep -A 1 -B 1 ongert  /etc/passwd
rfasdbal:x:4841:102:ASD baleni (Liberec Information System User):/users/cz/182/rfasdbal:/usr/bin/ksh
ongert:x:4842:102:Onger Tomas (Liberec Technical User):/users/cz/182/ongert:/usr/bin/ksh
krizovd:x:4843:102:Krizova Denisa (Liberec Production User):/users/cz/182/krizovd:/usr/bin/ksh
-bash-3.2$

Thanks a LOt guys! Love you!

I hope it is solved now.

druuna 08-21-2013 07:38 AM

Glad to see you got this fixed.

You can use -C instead of both -A and -B:
Code:

/usr/local/bin/grep -C 1 ongert /etc/passwd
BTW: Can you put up the [SOLVED] tag (upper right corener or Thread Tools menu).

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 05:49 PM.