LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 08-21-2013, 02:31 PM   #16
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,486

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354

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).
 
2 members found this post helpful.
Old 08-22-2013, 04:09 AM   #17
manalisharmabe
Member
 
Registered: Dec 2010
Posts: 240

Original Poster
Rep: Reputation: 1
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.
 
Old 08-22-2013, 04:24 AM   #18
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,332

Rep: Reputation: 400Reputation: 400Reputation: 400Reputation: 400Reputation: 400
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=.....
 
1 members found this post helpful.
Old 08-22-2013, 06:14 AM   #19
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
@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).

Last edited by druuna; 08-22-2013 at 03:13 PM.
 
2 members found this post helpful.
Old 08-23-2013, 02:18 AM   #20
manalisharmabe
Member
 
Registered: Dec 2010
Posts: 240

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by jlliagre View Post
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 !!
 
Old 08-23-2013, 02:23 AM   #21
manalisharmabe
Member
 
Registered: Dec 2010
Posts: 240

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Firerat View Post
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.
 
Old 08-23-2013, 02:41 AM   #22
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,332

Rep: Reputation: 400Reputation: 400Reputation: 400Reputation: 400Reputation: 400
Quote:
Originally Posted by manalisharmabe View Post
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 )
 
1 members found this post helpful.
Old 08-23-2013, 03:25 AM   #23
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,486

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.
 
1 members found this post helpful.
Old 08-23-2013, 04:02 AM   #24
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,332

Rep: Reputation: 400Reputation: 400Reputation: 400Reputation: 400Reputation: 400
yes as jlliagre points out, look for /usr/sfw/bin

really you need to figure out what you have installed on your system(s)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem using recursive grep (-r option) acomber Linux - Newbie 11 08-09-2012 01:33 AM
[SOLVED] using grep with -r option bibiki Linux - Newbie 4 02-20-2011 11:39 AM
understand -w option with grep geeyathink Programming 5 02-21-2008 04:17 AM
Paragraph-option to grep TheSpork Linux - General 2 03-17-2006 01:45 AM
grep option needed ziox Linux - General 7 01-04-2005 11:02 PM


All times are GMT -5. The time now is 10:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration