• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comaparing two files with ignoring lines

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Learn different string class methods.
They are very useful

Answer to your question try charAt(index) method.
reply
    Bookmark Topic Watch Topic
  • New Topic