perl -n -e 'print if /Twist 1/ .. /Twist 2/' testresults
The .. operator is cool!
--
<http://www.dave.org.uk>
European Perl Conference - Sept 22/24 2000
<http://www.yapc.org/Europe/> | [reply] [d/l] |
perl -n -we "print if /Twist 1/ .. /Twist 2/ and not /Twist \d/" test.
+txt
Which stripped out the flags too. However, I would bet there is a better way to do it that I am not able to think of at the moment. | [reply] [d/l] |
Hmm, how about:
perl -n -we "print if s/Twist 1// .. s/Twist 2// && ! /Twist \d/" text.txt
Untested, as I'm still sure what your data set is.
| [reply] [d/l] |
I would try the following:
perl -e 'while(<>) {print $1 if /Twist 1(.+)Twist 2/g;}' < testresults
but this is untested. | [reply] [d/l] |
perl -n -e 'if(/Twist 2$/){s/Twist 2//;print;} testresults'
Because you are going through the file line-by-line (default
behaviour when assuming a while loop around the program),
just test for the 'Twist 2' string at the end of the line. | [reply] [d/l] |
You'll want to use m//mg to match on a multi-line string (and undef $/ or something :), but the .. as davorg is a simpler way of doing it.
/brother t0mas
| [reply] |
Hey, it works!! What is the .. operator supposed to do? I've not seen it before..
Mike | [reply] |
Look at the section on "Range Operators" in perldoc perlop.
Basically, when used in a scalar context (like an if statement). It returns false until the left hand expression is true. It then returns true until the right hand expression becomes true.
Hope this helps.
--
<http://www.dave.org.uk>
European Perl Conference - Sept 22/24 2000
<http://www.yapc.org/Europe/>
| [reply] |