a perl question
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? Thank you! :\ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/847887.46702...@web121408.mail.ne1.yahoo.com
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! j...@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 j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ j...@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! j...@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! :\ > > > > > -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1294137620.2467.9.ca...@squeeje.critical.pt
Re: a perl question
On Tue, Jan 4, 2011 at 11:40 AM, Joao Ferreira gmail 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! > > > j...@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 > > j...@squeeje:~$ > j...@squeeje:~$ > j...@squeeje:~$ > j...@squeeje:~$ > j...@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?? -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/aanlktikfyl3-jhvchvr56arbh+6qejxssf3y4tpmg...@mail.gmail.com
Re: a perl question
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! > 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 -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/dfebv7xbgl@news.roaima.co.uk