srinu pearl wrote:I have a large text file of 1 GB size. I need to print the line when a matching word is found in a particular line. Below is the code I am using. But if there are many lines that has the matching word, it's taking lot of time.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Please, visit me for some cool tech post at www.ourdailycodes.com
UTF-16, surely?Luan Cestari wrote: . . . the Java String follows UTF-8, . . .
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie wrote:
UTF-16, surely?Luan Cestari wrote: . . . the Java String follows UTF-8, . . .
Please, visit me for some cool tech post at www.ourdailycodes.com
srinu pearl wrote:This is a interview question. I tried using pattern, it worked fast. But I am just able to search the word, but not able to print the line when match found.
int line = 0;
Pattern pattern = Pattern.compile("invalid holding");
txtscan = new Scanner(new File("C://logs/LM.2014-02-14.log"));
while (txtscan.findWithinHorizon(pattern,0) != null) {
System.out.println(line);
line++;
}
T.A. Nguyen
http://ta.cnci.org
http://www.linkedin.com/in/nguyenta
srinu pearl wrote:This is a interview question.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Don't get me started about those stupid light bulbs. |