Register
It is currently Sat Dec 20, 2014 6:44 pm

Finding lines that start with keyword, end with semicolon.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Thu Feb 09, 2012 12:23 pm   

Joined: Wed May 19, 2010 9:56 am
Posts: 21
Hello all,

I'm trying to capture lines that:
- start with a space,
- the word package,
- any letter sequence at all in the middle,
- and finally a semicolon on the end.

I been trying things like
Code:
grep '^ package [a-zA-Z]* ;$' /my/filename.


It seems so simple, but I haven't hit on the right syntax yet. Any ideas?


Top
 Profile  
 PostPosted: Fri Feb 10, 2012 2:59 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Use [[a-zA-Z]] or [[:alpha:]].

Quote:
^ package [[:alpha:]]* ;$


Your regexp should work, though. Can you show some sample text from the file?
Also, are you sure it's a space and not a tab, and that there is nothing left after the semicolon?


Top
 Profile  
 PostPosted: Mon Feb 13, 2012 7:04 am   

Joined: Wed May 19, 2010 9:56 am
Posts: 21
Actually it is the package line from many PERL modules such as:

package blosxom;

OR

package Test::YAML;


Top
 Profile  
 PostPosted: Mon Apr 02, 2012 5:56 pm   

Joined: Mon Feb 16, 2009 10:07 am
Posts: 19
Location: Paris - France
imho, you probably have a dos file : (\r\n) and not (\n) at end of line


Top
 Profile ICQ YIM  
 PostPosted: Tue Apr 03, 2012 9:28 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Are you accounting for the colons? What if you simplified it a bit?
Maybe something like: '^ package.*;$'

Does that match too much, or is it just not behaving like you expect it to at all?


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP