Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Want to search text file and get only certain information out.

Here is what I am trying to do.

I want to open a text file and search it for a line like "STOPPED READING HERE". If it finds the line then it will search from that point to the end of the document for a key phrase like "BROKEN PART".

If the text file does not have that "STOPPED READING HERE". Then I want to only read back a couple of days.

If it finds "BROKEN PART". Then I want to print everything associated with that. Then add a line "STOPPED READING HERE".  at the end of the document  Please see below.

Do you have any suggestions as to what would be the best way to do this.

Example of text file

April 20, 2005 12:28:34 PM
PART INSTALLED
Bla bla
Bla bla
Severity: Warning
___
April 20, 2005 12:29:01 PM
PART WORKING
Bla bla
Bla bla
Severity: Warning
___
April 20, 2005 12:30:01 PM ****THESE LINES WOULD BE EVERYTHING I WOULD WANT TO GET
BROKEN PART****THESE LINES WOULD BE EVERYTHING I WOULD WANT TO GET
Bla bla****THESE LINES WOULD BE EVERYTHING I WOULD WANT TO GET
Bla bla****THESE LINES WOULD BE EVERYTHING I WOULD WANT TO GET
Severity: Warning****THESE LINES WOULD BE EVERYTHING I WOULD WANT TO GET
___
0
NewMom2Brandon
Asked:
NewMom2Brandon
  • 2
1 Solution
 
Bob LearnedCommented:
Do you know how to read text?  Do you know how to examine input string for certain values?  

How much do you need?  Are you just looking for a helping hand?

Bob
0
 
NewMom2BrandonAuthor Commented:
I believe I would need to use StreamReader to read but the examples I have found said to read in the whole file and go from there. Streamwritter to write to the file (but need to have it at the end only)

If I want to check this textfile every hour or two. I don't want to read the whole file every time. If this file is large I would think it would take time.

I think what I really need is a suggestion as to the best way to start.
0
 
YurichCommented:
you don't have to read the whole file, you can read it line by line, using ReadLine() method of StreamReader class

regards
0
 
Bob LearnedCommented:
You could use a FileSystemWatcher, and listen for the Changed event, and then copy the file to another location, and input the text from there, so you don't have a file lock situation.

Bob
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now