Reputation: 2269
I have a file in which there is some data and then followed by lines of values. I need to retrieve only those lines where there is a set of two integers, four floats followed by a integer separated by a space. Can anyone please help me how to recognize only such lines and retrieve data from it?
Upvotes: 1
Views: 61
Reputation: 52185
From the way you mention your problem it seems that you already have a pattern. Using a regular expression such as ^\d+ \d+ \d+(\.\d+)? \d+(\.\d+)? \d+(\.\d+)? \d+(\.\d+)? \d+$
should match text like so: 23 24 1.2 3.6 9.1 5.0 4
.
So you could traverse your file one line at a time and use a pattern like the above to see if you have the line you want. I am assuming that you do not have other lines with the same pattern and that you do not want to match negative numbers.
Upvotes: 1