This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Comaparing two files with ignoring lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Comaparing two files with ignoring lines" Watch "Comaparing two files with ignoring lines" New topic
Author

Comaparing two files with ignoring lines

Rajita Stambhampelli
Greenhorn

Joined: Mar 08, 2012
Posts: 11
Hello Friends,
am trying to compare two log files using java, but in that comparision i would like to ignore some lines which strats with Rate, start, stop....etc.

and i would like to compare them avoiding the first 14 characters (DATE and time format)of the each line.

Dont know how to achieve this please suggest me in this
Thank you in advance
Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39
Hi Rajitha,
I have done a similar tool.
I will tell you steps and class imported so that you can apply your logic if the require is same

I have used BufferedReader to import a file in my Comparator class

1) Go to location of logfile1
2) Read the files in the constructor of the Comparator class
3) Read the logfile1
4) Write a compare method in the Comparator class which will take Comparator as an argument.
5) From logfile1 call the method by passing logfile2 as argument.
6) Take both files into a String array object.
7) Compare both files lengths if applicable.
8) Loop both arrays internally and compare for equality of both strings

I do not know if i answered your question well.........But i am trying to base my implemetation for your question.

If you want a design view, then think of classes and methods required keeping the above steps in mind.
Rajita Stambhampelli
Greenhorn

Joined: Mar 08, 2012
Posts: 11
Thank you for your suggestion,
i have done the same.
Comparing files is ok , but while comparing the files i would like to ignore some lines in both of them for e line 20 in both files contains the rate : 12 343 565 and rate : 36 7838 878 then it shouid not display as the difference.
So i have to ignore the line which starts with rate.
donot know how to achieve this
please help on this

Thank you in advance
Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39
Hi Rajitha,
Can you try using indexOf method and skip the comparison process there?


eg:
if (logfile1.indexOf("rate") && logfile2.indexOf("rate") )
continue;

Or you can also use logfile1.length method if applicable.
Rajita Stambhampelli
Greenhorn

Joined: Mar 08, 2012
Posts: 11
Thankyou Archana
i didnt try this
il try and il let you know. wheather it is working or not .
and one more thing
i would like to skip the first 14 characters while comparing.
any suggestions please

thank you in advance
Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39
Learn different string class methods.
They are very useful

Answer to your question try charAt(index) method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comaparing two files with ignoring lines