• 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

Based on the given input String ,read the entire line

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to scan the file and see if it contains the agentId(an input string) and print the entire line if it exists.Please find the code below for the same.



The problem is when I use the above condition it gives result even if some characters in the "String s" matches the currentline.

Clientlog:
2010-08-10 10:43:28,666 +0100 DEBUG [LogService] - (139.71.139.42) :: 2010-08-10 05:48:24,640 :: dkeely4 :: keepAlive :: Keep alive sent.
2010-08-10 10:43:29,307 +0100 FATAL [LogService] - (139.71.139.42) :: 2010-08-10 05:48:25,343 :: dkeely4 :: keepAlive :: Exception sending keep alive:

Please suggest me.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it gives result even if some characters in the "String s" matches the currentline.



As it should based on the String API. Think about it. If your agentId value is "XYZ" and there is some other value in the record which contains the value "WXYZ" how do you know contains(CharSequence) returned true from the desired field (in this case agentId) in the record.

You may want to rethink your approach. If this is structured data, maybe extract the agentId from a specific index range using the substring method or looking for certain delimiters to get the field position for agentId. If it's unstructured data then maybe do some further analysis to figure out how to extract the actual agentId field value.
 
dileep keely
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The logs that I have is in a structured format with the agentId at the same position,I will use the subString() for this.
Will check the other logs as well in some other folders.
reply
    Bookmark Topic Watch Topic
  • New Topic