Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > grep specific info from a file

Reply
Thread Tools

grep specific info from a file

 
 
Mr_Noob
Guest
Posts: n/a
 
      02-25-2008
Hi all,

What is the best way to grep into a file, only lines beginning with
"[" and ending with "]" ?
And then, how can I feed an array with the information contained
between the 2 brackets, without the 2 brackets?

here is a sample of my file :

....
[blah blah blah]
some stuff here

[blabla again]
here is some other stuff here too
....


What I'd like to obtain is :

....
bla blah blah
blabla again
....


thanks in advance for ur help
Regards
 
Reply With Quote
 
 
 
 
Mr_Noob
Guest
Posts: n/a
 
      02-25-2008
Exactly !
Thanks a lot !

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-25-2008
Mr_Noob <> wrote:
>What is the best way to grep into a file, only lines beginning with
>"[" and ending with "]" ?
>And then, how can I feed an array with the information contained
>between the 2 brackets, without the 2 brackets?


Just loop through the file. For each line if it m//atches the condition (no
need for grep()) then push() the substr()ing portion into the array.

Other ways:
- to check for first/last character just extract them via substr() and
compare to "[" resp. "]"
- if you inlcude then center portion in your RE for m//, then you can group
it and just push $1 into the array.
- slurp the whole file into the array, then grep() for the right lines, then
discard leding/trailing square brackets

I am sure there are many more variation.

jue
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML parsing problem finding a specific element in a specific place mazdotnet ASP .Net 2 10-02-2009 10:07 AM
Parsing DOM to search specific tags with specific custom attribute William FERRERES Javascript 7 07-09-2007 08:11 PM
Is ViwState Page-Specific or UserControl-Specific =?Utf-8?B?SmF2?= ASP .Net 2 08-16-2006 09:30 PM
redirect traffic on specific ip to specific interface mimiseh Cisco 3 06-05-2005 09:14 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments