Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Extract/Read Data from a file between a particualar time frame  RSS feed

 
Varshini Priya
Ranch Hand
Posts: 95
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


I have a huge file and I wanted to extract the lines availble in the file between a particular time frame.


Note: The file has a specific format in each line of the log specifies Date/Time.Also Not all the lines in the logfile has date/Time stamp present in it . When there are errors during a particular time, the exceptions are also thrown in the file for that time. I want to extract all the data for a particular day or days along with the exception details as well

the file in the below format,




05/21/2010 10:05:48 INFO [main] [MS:ConfigurationCache] - --preLoad passwordPolicyConfiguration.
05/25/2010 10:05:48 INFO [main] [MS:PasswordPolicyConfiguration] - Loaded PasswordGenerationConfiguration.



In the above case, what do I do to extract the data from 05/21/2010 to 05/25/2010.


Please suggest what should I use to extract this data. Should I use Pattern matching /Regular expressions to read/match? Please suggest. Thanks
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see this as requiring one to read the file a line at a time or to use of regular expressions. I would do this using one of the sequential string matching algorithms such as the Knuth Morris Pratt (KMP) algorithm. KMP does not require any backtracking so it allows one to process the file a character at a time until a match of the required start date is found. One then uses KMP again to process the file until the day after the end of file is found. During this second phase one writes the file content to wherever one wants.

Note, to read the file efficiently one should use a BufferedReader.

For KMP, Google is your friend.
 
kc pradeep
Greenhorn
Posts: 29
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very similar requirement... can someone explain this in some detail, may be with some code snippet....
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!