The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Put the output of grep in a variable big123456 Shell Programming and Scripting 3 04-23-2008 08:40 AM
Redirect grep output into file !!!!! hanu_oracle Shell Programming and Scripting 2 04-10-2008 06:02 AM
output of grep useless79 Shell Programming and Scripting 3 09-18-2007 02:36 AM
substitute the grep output jasmeet100 Shell Programming and Scripting 1 10-11-2005 04:40 PM
Pausing a Grep output mharley Shell Programming and Scripting 5 06-15-2005 01:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-04-2004
Registered User
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 124
Question Strange output from grep

Hi,

I am getting different output for grep depending which directory I am in.
The following is a transcript of my session, I am using egrep but have also used grep –E. The directory names have been changed for security:

$pwd
/dir1/dir2/dir3/dir4
$echo 000000 |egrep -v [0-1][0-9][0-5][0-9][0-5][0-9]
$echo $?
1
$cd ..
$pwd
/dir1/dir2/dir3
$echo 000000 |egrep -v [0-1][0-9][0-5][0-9][0-5][0-9]
000000
$echo $?
0
$cd ..
$pwd
/dir1/dir2
$echo 000000 |egrep -v [0-1][0-9][0-5][0-9][0-5][0-9]
$echo $?
1
$

It appears the output from egrep when run in directory /dir1/dir2/dir3 is the opposite of what I would expect

/dir1/dir2/dir3 and /dir1/dir2/dir3/dir4 are on the same volume.
I have checked and there is only one instance of egrep on the whole server.
The permissions of the directories are as follows

drwxr-xr-x /dir1/dir2
drwxrwxrwx /dir1/dir2/dir3
drwxr-xr-x /dir1/dir2/dir3/dir4

We can’t work out why this is happening. Can anyone help?

Many thanks
Helen
Reply With Quote
Forum Sponsor
  #2  
Old 11-04-2004
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,295
if there is a . in your PATH variable does it come before /usr/bin ?
Reply With Quote
  #3  
Old 11-05-2004
Registered User
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 124
There is a . in the path but it is the very last item. I have done a 'which egrep' in each of the directories and they all point to the same egrep.
Reply With Quote
  #4  
Old 11-05-2004
Registered User
 

Join Date: Oct 2004
Posts: 8
Use full path

It's very wierd.
Can you try

echo 00000 | /usr/bin/egrep ....

just to avoid path suspisions?
Reply With Quote
  #5  
Old 11-05-2004
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Quote:
$echo 000000 |egrep -v [0-1][0-9][0-5][0-9][0-5][0-9]
000000
Why are you looking at egrep - it seems to me, it the echo that is messed up (or the pipe). Note that echo is actually echoing 000000 back to you instead of going through the pipe.

Also post your OS and version - I could not duplicate your problem on Solaris 2.6.
Reply With Quote
  #6  
Old 11-05-2004
Registered User
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 124
It came out with the same output

$echo 000000 |/usr/bin/egrep -v [0-1][0-9][0-5][0-9][0-5][0-9]
000000

I also tried this which was interesting:

$echo 000000 |/usr/bin/egrep -v [0-1]
$echo 000000 |/usr/bin/egrep -v [0-1][0-9]
$echo 000000 |/usr/bin/egrep -v [0-1][0-9][0-5]
$echo 000000 |/usr/bin/egrep -v [0-1][0-9][0-5][0-9]
$echo 000000 |/usr/bin/egrep -v [0-1][0-9][0-5][0-9][0-5]
$echo 000000 |/usr/bin/egrep -v [0-1][0-9][0-5][0-9][0-5][0-9]
000000
$

Its bizarre.
Reply With Quote
  #7  
Old 11-05-2004
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
use the path when using the echo command instead of possibly using the shell's echo.

Also, I got mine to error with the same output by adding an extra [0-9] on the egrep.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0