1827889 Members
1814 Online
109969 Solutions
New Discussion

Re: grep and regexp

 
SOLVED
Go to solution
Shawn_45
Occasional Advisor

grep and regexp

It seems that word delimiter \< and \> doesn't seem to work as expected.

I have a file that contains words "The", "There", "These", etc. but

grep \
Any ideas?

Shawn
11 REPLIES 11
Volker Borowski
Honored Contributor

Re: grep and regexp

grep -e '\
Shawn_45
Occasional Advisor

Re: grep and regexp

It didn't work. still nothing. in csh, this command yields all the lines that start with , etc.
Balaji N
Honored Contributor

Re: grep and regexp

hi,
does this help. it is on bash. btw, what shell are u working on.

++++++++++++
cat a.txt
It seems that word delimiter \< and \> doesn't seem to work as expected.

I have a file that contains words "The", "There", "These", etc. but

grep \
Any ideas?

Shawn
[balajin@penguin tmp]$ grep 'rk\>' a.txt
It seems that word delimiter \< and \> doesn't seem to work as expected.
[balajin@penguin tmp]$ grep '\ It seems that word delimiter \< and \> doesn't seem to work as expected.
I have a file that contains words "The", "There", "These", etc. but
++++++++++++

Regards
Balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Dietmar Konermann
Honored Contributor

Re: grep and regexp

Hi, Shawn!

The question seems to be, what do you exect from "\<"... and why do you expect it? :-)

The grep command understands RE and ERE (with -E) as described in rexexp(5).

You could use this ERE:

grep -E '([[:space:]]|^)T'

This matches any "T" at the beginning of the line (^) or (|) being preceded by a whitespace ([[:space]]).

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
H.Merijn Brand (procura
Honored Contributor

Re: grep and regexp

He expects 'start of word', as every 'vi' user once does :)

Modern egrep's support this feature (grep does not)

# egrep '\
This feature is one of the escapes that is not normalized accross the pattern matching programs. vi uses \<, as does egrep. emacs, .net, and sun's java package support the perl \b escape (emacs also supports \< and \>, but emacs lacks a decent user interface)

If you compile grep/egrep/fgrep yourself from the source, and you already have PCRE (perl compatible regular expressions) installed, it also supports PCRE like regex syntax through -P:

lep a5:/pro/local/bin 112 > grep --help
Usage: grep [OPTION]... PATTERN [FILE] ...
Search for PATTERN in each FILE or standard input.
Example: grep -i 'hello world' menu.h main.c

Regexp selection and interpretation:
-E, --extended-regexp PATTERN is an extended regular expression
-F, --fixed-strings PATTERN is a set of newline-separated strings
-G, --basic-regexp PATTERN is a basic regular expression
-P, --perl-regexp PATTERN is a Perl regular expression

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
David_246
Trusted Contributor

Re: grep and regexp

Hi Shawn,

For the start of the sentence :

grep ^The.* /tmp/2

Somewhere in the middle :

grep the.* /tmp/2

Regs David
@yourservice
Shawn_45
Occasional Advisor

Re: grep and regexp

Hi all,

I know most of you have way passed the level beyond the certificate books. What I was doing was to understand the materials presented in Rehman's book.

Page 95: Use of the Word Delimeters \< and \>

It simply didn't work. reason I could think of was that the system version I am running is not the latest:

$uname -r
B.10.20

To answer other's question, I am using posix shell.

As a separate topic, although I found the book is overall well written, some sentences were a bit hard to understand. For example,

Page 108 Changing the Owner and Group of a File.

...
"Any user other than the owner of the file can't change ownership of a file, except the superuser."

Doesn't this mean

"Only the owner and the superuser can change the ownership of a file"?

Thanks for all your responses. I will give you points when I finish next chapter. :-)

Shawn
Dietmar Konermann
Honored Contributor

Re: grep and regexp

Hi, Shawn!

If you issue grep '\
As Merijn wrote, _some_ grep implementations allow that... but not the HP-UX versions. Even not the latest ones.

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Shawn_45
Occasional Advisor

Re: grep and regexp

OK, I get it. I guess I don't have to ask next question: why did he put this in the book if this is not implemented? Am I supposed to assume that materials covered in the book are for HP-UX exam? Thanks for your explanation.

Shawn
Chris Vail
Honored Contributor
Solution

Re: grep and regexp

You asked:
>Any user other than the owner of the file can't change ownership of a file, except the superuser."

>Doesn't this mean

>"Only the owner and the superuser can change the ownership of a file"?

The Rahman book is good, but sometimes (as you point out) his use of English is strained. The answer is: yes--only the owner of a file and/or the superuser can change the permission or ownership of that file.

The book has other areas of difficulty: pay STRICT attention to the networking theory. It almost doesn't cover it in the depth asked on the test.


Chris

Dennis Handly
Acclaimed Contributor

Re: grep and regexp

(Adding this reply again.)
On 11.11, grep has a new -w option to do word searches.