The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk, sed, grep...weird style finalight Shell Programming and Scripting 13 05-19-2008 11:30 PM
Weird rsync behavior scotbuff OS X (Apple) 2 12-24-2007 02:05 PM
Weird behavior on a Sun Fire V120 running solaris 10. jsandova SUN Solaris 2 10-05-2007 03:17 PM
sed behavior on hp-ux andy2000 Shell Programming and Scripting 8 05-04-2007 06:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2007
Registered User
 

Join Date: Dec 2007
Posts: 14
Stumble this Post!
weird behavior of grep -P

I met a problem in using grep -P.

There is a text file, temp.txt, whose content is:
dddd
abc

I ran the command:

grep -P "\s*abc" temp.txt

The result I expected is:
abc

But, the actual result is:
dddd
abc

Could anyone tell me what is wrong?

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-20-2007
DeepakS's Avatar
Registered User
 

Join Date: Aug 2006
Posts: 60
Stumble this Post!
Quote:
Originally Posted by pankai View Post
I met a problem in using grep -P.

There is a text file, temp.txt, whose content is:
dddd
abc

I ran the command:

grep -P "\s*abc" temp.txt

The result I expected is:
abc

But, the actual result is:
dddd
abc

Could anyone tell me what is wrong?

Thanks.
\s in perl includes \n so the pattern matches dddd\nabc

Depending on your requirements you could do a "^\s*abc" or "\w*abc"
Reply With Quote
  #3 (permalink)  
Old 12-20-2007
Registered User
 

Join Date: Dec 2007
Posts: 14
Stumble this Post!
Quote:
Originally Posted by DeepakS View Post
\s in perl includes \n so the pattern matches dddd\nabc

Depending on your requirements you could do a "^\s*abc" or "\w*abc"
Got it. Thanks.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0