The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-20-2008 02:30 AM
Weird rsync behavior scotbuff OS X (Apple) 2 12-24-2007 06:05 PM
Weird behavior on a Sun Fire V120 running solaris 10. jsandova SUN Solaris 2 10-05-2007 06:17 PM
sed behavior on hp-ux andy2000 Shell Programming and Scripting 8 05-04-2007 09:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-20-2007
pankai pankai is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 14
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.
  #2 (permalink)  
Old 12-20-2007
DeepakS's Avatar
DeepakS DeepakS is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 74
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"
  #3 (permalink)  
Old 12-20-2007
pankai pankai is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 14
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0