[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: a perl question



S Mathias <smathias1972@yahoo.com> wrote:
> cat asdf.txt
> bla-bla
> bla-bla
> bla[XYZ]
> importantthing
> another important thing
> [/XYZ]
> bla-bla
> bla-bla
> [XYZ]
> yet another thing
> hello!
> [/XYZ]
> bla-bla
> etc.
> $ SOMEPERLMAGIC asdf.txt > output.txt
> $ cat output.txt
> importantthing
> another important thing
> yet another thing
> hello!


> how can i sovle this question? what is SOMEPERLMAGIC? are there any
> perl gurus, that have a little spare time?


What are your criteria? Matching "important" or "hello" somewhere in the
text? Something else? It's really not clear by your example what is to
be captured.

For example, if it's "important" or "hello" then personally I'd use
egrep and avoid the complexity of perl entirely:

    $ egrep 'important|hello' asdf.txt
    importantthing
    another important thing
    yet another thing
    hello!

    $ perl -ne '/important|hello/ && print' asdf.txt
    importantthing
    another important thing
    yet another thing
    hello!

Chris


Reply to: