| 1. |
Solve : dos for command? |
|
Answer» I have a file LOG file for which I need to read each line. If a line in the log file starts with the word 'Record' or 'ORA' I want to capture the complete line and write it to a new file. ...the above method calls findstr for each line iteration. If there are 10000 lines, then findstr will be called 10000 times, which is inefficient. better to use it the other way round , ie Code: [Select]for ..... ( findstr "ORA Record" mainlog.txt ) do blah blah if there are further processing on each line found, or simply pipe to newfile if what OP wants is only to find ORA records Code: [Select]findstr [blah options] "text_to_find" >>newfile ghost, You are right the for loop is not needed: Code: [Select]@echo off echo. > newnewfile.txt findstr "ORA Record" mainlog.txt >> newnewfile.txt type newnewfile.txt Output: C:\>type newnewfile.txt Record bbbbbbbbbbbbbbbbbb ORA xxxxxxxxxxxxxxxxxxxxxxxx C:\> p.s. Works just like the Unix grep command. Quote from: billrich on June 12, 2009, 07:42:31 AM p.s. Works just like the Unix grep command.and also awk/sed. these tools iterate files and find patterns so they are similar. however, awk goes a bit more in that it is a programming language by itself. therefore, one does not need to learn grep/sed and use only awk to do the job( of MANY , eg cut, wc). this will reduce your learning curve a lot. |
|