Can I use FINDSTR to move selected text from a file and move to another ?

Posted on 2004-08-30
Last Modified: 2008-01-09
I have a log file that I want to split into multiple files based on text inside the file.
For example, this log file is concatenated throughout the day, but our client would like pieces of the log as the are generated.
The good thing is that each line begins with timestamp so it looks something like this:
08:15:49   Group Totals Record at line . . .
08:15:49   Blah blah . . .
08:15:49   Number of Records at line # 3352 Blah blah . . .
08:15:50   End of Job.
10:30:07   Blah blah . . .
10:30:07   Blah blah . . .
10:30:08   Blah blah . . .

I would want to send the lines after 10:30:07 to another file.
Is this possible ?
Thanks in advance
Question by:MGray55

Expert Comment

ID: 11930868
Install cygwin from redhat (free product) or get GREP free from Borland (or any other GREP implementation you wish to use, GREP is short for Gnu Regular ExPressions).

To do what you want, I.ex get all the "10"'s in a file,

grep "10:" infile >outfile

To get anything BUY the timestamps at 10:00 (inverse matching),

grep -v "10:" infile >outfile

Etc.. You get the idea, modify the examples to fit your needs :)

LVL 19

Accepted Solution

akoster earned 125 total points
ID: 11932229
you can do the trick in plain batch as well...

try making a for loop which scans each line and then assigns this line to a variable, say %%A
with the delimeter set to : this means that the actual hour is represented in %%A, minutes in %%B and seconds in %%C.

with a simple if %%A GTR 10 clause you can then reroute the total line to a new file if neccessary

for help on "for", "if", and "gtr" statements just type help in a command box.

Assisted Solution

joelleo earned 125 total points
ID: 11935540
Aloha MGray55.

Using findstr you should have no problems doing what you'd like.

findstr "^10:" logfile.txt > newlog.txt

would output any line that begins with 10: to newlog.txt. That would include anything that was logged between 10:00:00 and 10:59:59.

This is a simple thing to do, but it's a manual process. If your boss wants you to give out anything that's occurred within the hour this works great. it becomes a bit more difficult if you are looking for "anything after 10:00:00." If you know roughly the # of lines in the log file, you could even just do a tail -n to copy out just the last n lines of the file.

Good luck!


Author Comment

ID: 11942084
My requirements have changed, but I should be able to figure out something similar with your answers.
This script is being run on a server where I cannot install any utilities or third party products. Your answers should let me do it through straight DOS.

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now