- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- egrep doesn't work
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2003 06:34 AM
05-13-2003 06:34 AM
This question is for real UNIX-cracks ;-)
Initial position:
script: /etc/profile.company-sysconf
called file from the script: /tools/data/domain
- directory /tools/ have drwxr-xr-x root root
- directory /data have drwxr-xr-x snml dba
- file 'domain' have -rwxr-xr-x snml dba
We have a shell-script with the command:
cat /tools/data/domain | egrep [a-z]
We use this command on 53 machines. It works fine on 52 machines. It doesn't work only by one (!!!) machine.
All machines are similar.
The script and the file 'domain' are both copys from a other machine (we tried it from different machines).
We think, it isn't the problem from the script, because if we make this 'cat ..| egrep' command from the command line it doesn't work too!
It works with the following 'settings':
root# cd /tools/data/
root# cat domain | egrep [a-z] --> fine
root# cd /
root# cat /tools/data/domain --> fine (without egrep)
other users$ cat /tools/data/domain | egrep [a-z] --> fine
It DOESN'T work only with root (!!):
root# cat /tools/data/domain | egrep [a-z] --> bad
We was checking also the environments, we think everything is the same.
Have somebody any ideas. It is very strange
Thank you very much - Konrad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2003 06:39 AM
05-13-2003 06:39 AM
Re: egrep doesn't work
You might need to use explicit path:
/usr/bin/egrep
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2003 06:45 AM
05-13-2003 06:45 AM
Re: egrep doesn't work
# egrep [a-z] /tools/data/domain
works much more efficient
2. the fact that it does not run most likely finds its existance in the fact that a file exists with a one character name in the rang of a..z
You should quote th regular expression, because it is also recognized by the shell
So, .... how does
# egrep '[a-z]' /tools/data/domain
work for you?
Are the versions of (e)grep the same along the line of machines?
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2003 11:24 PM
05-13-2003 11:24 PM
Re: egrep doesn't work
Use 'type egrep' to find out where from.
BTW egrep is obsolescent.
You should use grep -E.
And, as per previous post, the use of 'cat' is superfluous
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 01:22 AM
05-14-2003 01:22 AM
Re: egrep doesn't work
you must enclose the pattern in single quotes. If not,
[a-z]
will be expanded to any file whose name matches this pattern. For example: a file whose name os 'a' exists in your current directory. The following command line:
$ egrep [a-z] /etc/profile
is execute as:
$ egrep a /etc/profile
This is because shell expands and substitutes file patterns.
If no filename matches the pattern, shell doesn't substitute the pattern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 03:45 AM
05-14-2003 03:45 AM
Re: egrep doesn't work
- /usr/bin/egrep doesn't help.
- all egrep's are from /usr/bin/egrep (which or type command).
-# egrep '[a-z]' /.../domain works fine (also with the cat-command). I think, this is a very good workaround, or it is THE solution.
But why I have this problem only by one machine (from 53!)?
The tip to work without 'cat ... | egrep' is good, but for me it is easier to read the script if I use it in 'my way'. And for 'save' CPU time, it's definitiv not necessary. But thank you anyway - I'm a rookie and I have to learn a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 04:17 AM
05-14-2003 04:17 AM
Solutiontouch a
echo [a-z]
a
In other words, the [a-z] is a regular expression which, unless enclosed in single quotes or the brakets escvaped with backslashes: \[a-x\] then the shell expands the expression BEFORE egrep ever sees the characters on the command line. Try this:
echo ?
You'll see all the files in the current directory that are exactly 1 character names. Another way to see this is to take your failing command and put echo in fron of it:
echo egrep [a-z]
then protect the expression:
echo egrep '[a-z]'
Most people forget that the shell automatically looks for regular expressions and tries to perform a match.
In addition to the recommendation to not use cat into egrep, egrep itself is overkill since it has extra code to process extended regular expressions, and a character class such as [a-z] is no an extended regexp. Plain old grep will work fine with your example. An example of an extended regexp is:
egrep 'err|warn|fail' some_file
which finds all lines with any of the 3 strings. However, egrep isn't even necessary for the above task as multiple -e options will do the same thing:
grep -e err -e warn -e fail some_file
Bill Hassell, sysadmin