a perl question

Joao Ferreira gmail joao.miguel.c.ferreira at gmail.com
Tue Jan 4 11:13:29 UTC 2011


On Tue, 2011-01-04 at 22:05 +1100, Karl Auer wrote:
> > $ SOMEPERLMAGIC asdf.txt > output.txt
> > how can i sovle this question? what is SOMEPERLMAGIC? are there any
> perl gurus, that have a little spare time?
> 
> It's not clear from your "sample data" what it is you are trying to
> do.
> What distinguishes the lines you want to keep from the lines you want
> to
> discard? 

from [XYZ] line to [/XYZ] line ;) ... I guess !

solution:

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







More information about the ubuntu-users mailing list