Reputation: 55
I have an input text file in this format:
JAN Year FEB Year MAR Year APR Year MAY Year
9.0 1916 9.8 1998 12.1 2012 16.9 1992 15.7 2011 8.7 2007 8.9 2008 11.9 1938 15.2 2007 16.8 2008 9.0 1916 9.8 1998 12.1 2012 16.9 1992 15.7 2011 8.7 2007 8.9 2008 11.9 1938 15.2 2007 16.8 2008 9.0 1916 9.8 1998 12.1 2012 16.9 1992 15.7 2011 8.7 2007 8.9 2008 11.9 1938 15.2 2007 16.8 2008
How can i parse above file? how can i get values of Month and year from above file in column wise fashion ?
I want to store value of each month for given year...
Help me...
Upvotes: 0
Views: 77
Reputation: 44
you can use Perl or TCL ,its easier to make parser of text file in these scripting languages
perl has got modules for different things , but for above file you just need to learn " regular expressions "
Upvotes: 1
Reputation: 401
First split the string with string.split()
which returns an array of words in the string separated by the delimiter (default is white space) .
Then, while looping over the new array of strings keep in mind that :
all odd-numbered indices are the month.day, so split that by string.split('.')
All even-numbered indices are year.
Happy parsing
Upvotes: 1