Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
04-27-2011, 02:14 AM #1
- Join Date
- Apr 2011
- Thanked 0 Times in 0 Posts
Pattern matching and array methods
I have a text file that is structured like so:
I would like to be able to print out a subset of the file ie: print the line beginning with 1:2 through the line beginning with 1:4
So far, I've started with this;
lines = File.readlines("file.txt")
line is 1:1 abcdefg
line is 1:2 abcdefg
line is 1:3 abcdefg
If I want to print out the lines that start with 1:2 through 1:4, how should I proceed? Some of the text files won't be "aligned" in that line won't always be 1:1. If a user would like to print the lines containing 3:9 - 3:31, how can I scan each line of the array and pattern match the boundaries (3:9 - 3:31 in this example)?
Thanks in advance for any information that could point me in the right direction.