Improve company productivity with a Business Account.Sign Up


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

Posted on 2004-08-30
Medium Priority
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

Arno Koster earned 375 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 375 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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

607 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