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

Re: a perl question



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!
jmf@squeeje:~$ 


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


not a guru... I just love it... perl rules :)

joao


> 
> Thank you! :\
> 
> 
>       
> 
> 



Reply to: