grep specific info from a file

Discussion in 'Perl Misc' started by Mr_Noob, Feb 25, 2008.

  1. Mr_Noob

    Mr_Noob Guest

    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
     
    Mr_Noob, Feb 25, 2008
    #1
    1. Advertising

  2. Mr_Noob

    Mr_Noob Guest

    Exactly !
    Thanks a lot !
     
    Mr_Noob, Feb 25, 2008
    #2
    1. Advertising

  3. 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
     
    Jürgen Exner, Feb 25, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmF2?=

    Is ViwState Page-Specific or UserControl-Specific

    =?Utf-8?B?SmF2?=, Aug 16, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    546
    =?Utf-8?B?SmF2?=
    Aug 16, 2006
  2. Charl

    Print specific info

    Charl, Jan 15, 2007, in forum: HTML
    Replies:
    7
    Views:
    384
    Jonathan N. Little
    Jan 15, 2007
  3. Stephanie
    Replies:
    0
    Views:
    282
    Stephanie
    Dec 30, 2008
  4. mazdotnet
    Replies:
    2
    Views:
    405
    Alexey Smirnov
    Oct 2, 2009
  5. William FERRERES
    Replies:
    7
    Views:
    220
    William FERRERES
    Jul 9, 2007
Loading...

Share This Page