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

Re: a perl question



On Tue, Jan 4, 2011 at 11:40 AM, Joao Ferreira gmail
<joao.miguel.c.ferreira@gmail.com> wrote:
> On Tue, 2011-01-04 at 02:27 -0800, S Mathias 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!
>
>
> jmf@squeeje:~$ 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
>
> jmf@squeeje:~$
> jmf@squeeje:~$
> jmf@squeeje:~$
> jmf@squeeje:~$
> jmf@squeeje:~$ cat asdf.txt  | perl -e 'my $important =0; while (<>) {if
> (/\[XYZ\]/) {$important = 1;next;}; if (/\[\/XYZ\]/){$important=0;next};
> if ($important) {print;}};'
> importantthing
> another important thing
> yet another thing
> hello!

Or use ".." range operator:
perl -ne 'print if (/\[XYZ\]/../\[\/XYZ\]/ and not /\[\/?XYZ\]/)'

PD: Should I add "OT: " to subject , or is it not ok doing that when
thread is started??


Reply to: