- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep -E (with regular expression) \b
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
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
03-12-2004 08:30 AM
03-12-2004 08:30 AM
grep -E (with regular expression) \b
I'm trying to use grep -E (regular expression)
with \b (word boundary) in csh without success.
(grep -E $path '\b\/usr....\b')
Is there any way to use \b, \s etc with grep?
Thanks.
Reggie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 09:02 AM
03-12-2004 09:02 AM
Re: grep -E (with regular expression) \b
at 11.11 grep has the -w option that matches only words
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 09:10 AM
03-12-2004 09:10 AM
Re: grep -E (with regular expression) \b
I'm using 10.20. I don't know what
version if grep it is, but it is located
at /usr/bin.
Thanks.
Reggie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 09:15 AM
03-12-2004 09:15 AM
Re: grep -E (with regular expression) \b
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 09:22 AM
03-12-2004 09:22 AM
Re: grep -E (with regular expression) \b
Thank you for the info.
I did not see -w in grep man page.
I'll find some other way since I'm
stuck with 10.20 at this moment.
Thanks.
Reggie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 09:23 AM
03-12-2004 09:23 AM
Re: grep -E (with regular expression) \b
grep -E '[:space:]...[:space:]'
or
grep -E '[:blank:]...[:blank:]'
not even the -w switch is going to work for you in this case because both : and / are non word characters
your going to have to use perl or write your own
function notInPath {
typeset field
print $2 |
awk -v field=$1 -F: '{
if (NR > 1) exit;
for ( i=1; i<=NF; i++ ) {
if ( field == $i ) exit 1;
}
exit 0;}'
return
}
notInPath /usr/bin $PATH
if [[ $? = 0 ]] ;then
print "not in path"
else
print "it is in the path"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 01:20 PM
03-12-2004 01:20 PM
Re: grep -E (with regular expression) \b
Thanks a lot for the info.
Please forgive my dumb questions.
Is function notInPath in Perl?
Does shell script (C-shell or others)
support function?
Best regards,
Reggie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 04:55 PM
03-12-2004 04:55 PM
Re: grep -E (with regular expression) \b
still using posix shell syntax, but using perl instead of awk
print "$PATH" |
/opt/perl/bin/perl -F: -ane '
foreach $str (@F) {
if ( $str =~ m|^/usr/bin$| ) {
exit 1;
}};exit 0;'
if [[ $? = 0 ]] ;then
print "not in path"
else
print "it is in the path"
fi
the above example doesn't use a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 05:14 PM
03-12-2004 05:14 PM
Re: grep -E (with regular expression) \b
print $PATH |
tr ":" "\012" |
grep -x /usr/bin >/dev/null 2>&1
if [[ $? = 0 ]] ;then
print "/usr/bin is in \$PATH"
else
print "/usr/bin is not in \$PATH"
fi
of if you like to switch the logic
num=$(print $PATH |
tr ":" "\012" |
grep -cx /usr/bin >/dev/null 2>&1)
if [[ $num = 0 ]] ;then
print "/usr/bin is not in \$PATH"
else
print "/usr/bin is in \$PATH"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 09:36 PM
03-12-2004 09:36 PM
Re: grep -E (with regular expression) \b
echo $path|perl -ne "if(/\b\/usr...\b/){print}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 10:18 PM
03-12-2004 10:18 PM
Re: grep -E (with regular expression) \b
if you have to use a regular expression you probably have to adapt it to your needs. The following is just a suggestion:
# grep -E "(^|[^a-zA-Z0-9])ordet([^a-zA-Z0-9]|$)" infile
which will try to look for the literal string
ordet
in infile. It does not take boundaries like e.g. special characters or tabs into account, but has already developed into something that gives unix a reputation as not easily understandable.....
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2004 02:08 AM
03-13-2004 02:08 AM
Re: grep -E (with regular expression) \b
in this case the data being compared makes using word boundaries impossible. He wants to do this on his path variable, a colon delimited string of directory names. In this situation the word boundary is :/, which isn't matched by perl's \b. \W comes closer, but still won't match if what he is looking for is at the begining of the line. And \W\/usr\/bin\W/ will match both /usr/bin and /usr/bin/X11.
So, you end up doing something like
s/^/ /;tr /:/ /;if ( \W\/usr\/bin\W/ )
to get it to work that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2004 06:24 AM
03-13-2004 06:24 AM
Re: grep -E (with regular expression) \b
Bill Hassell, sysadmin