954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

searching algorithm

hello all
i have a jap project.in which i have a lot of log(txt) files.what i want to do is searching a particular number in all log files and cut some fields of lines containing that number and show them as table in jsp page.

currently i am using shell scripting for searching and cut fields.but it is taking too much time to search and show data in jsp page.Can ANY ONE please help me

manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 10
Solved Threads: 1
 

Hey,
This would help you i guess. Correct me if i'm wrong

public static void Search(String filePath, String search, String ignoreCase)
			throws IOException {

		FileInputStream fstream = new FileInputStream(filePath);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String str, str1;

		boolean l_found = false;
		int j = 1, k = 0;

		while ((str = br.readLine()) != null) {
			for (int i = 0; i < str.length(); i++) {

				// Ignoring case of the string
				if (ignoreCase == "Y") {
					str1 = str.toLowerCase();
					search = search.toLowerCase();
				} else
					str1 = str;

				if (i + search.length() <= str.length()) {
					if (search.equals(str1.substring(i, i + search.length()))) {
						System.out.print("In Line : " + j);
						System.out.println("  " + str);
						l_found = true;
						k++;
					}
				}
			}
			j = j + 1;
		}
		System.out.println("Total Match Found : " + k);
		if (!l_found)
			System.out.println(search + " String not found on the file");

	}
kingman123
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: