Solved

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

Posted on 2004-08-30
4
670 Views
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
0
Comment
Question by:MGray55
4 Comments
 

Expert Comment

by:bjorn_rohlen
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 :)

-Bjorn
0
 
LVL 19

Accepted Solution

by:
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.
0
 
LVL 3

Assisted Solution

by:joelleo
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!

Joel
0
 

Author Comment

by:MGray55
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello I read in a discussion about a person who configured a very simple mirror RAID with two hard drives; the system and data were on the same partition. He asked how to repair the system as it was not booting up anymore. In his case running …
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
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.

864 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

19 Experts available now in Live!

Get 1:1 Help Now