Solved

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

Posted on 2004-08-30
4
671 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to LibreOffice 24 88
ovirt 3.6 guest VM support oracle solaris 4 75
Search also sub-folder 1 66
AS400 user directory 6 113
Just about everyone has an old PC laying around.  Ask anyone in the IT industry, whether they are a professional or play in it as a hobby.  From outdated Desktops to cheap "throwaway" laptops, they are all around and not as hard to "fix up" as you m…
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…
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.

773 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