Hi experts, How can I search for multiple occurence of a particular string in a series of textfile using DOS? Once it has found each occurence, it will copy the whole line of that occurence to a seperate file, for example "C:\temp.txt". Once this is done, it will continue with the next text file in the folder.
Thanks everyone.

Seems kind of odd that the last several threads have been about manipulating text files with search routines. Are you all in the same programming class?
Hi Dan Could be a bit tricky in DOS.
LOL
=====================================
If at first you don't succeed, you're about average.M2
Hey all, Lol..no man. Its actually for work. I tried manipulating them using VBA, but I'm limited to the number of lines in Excel to do it. So i figured DOS would be able to do something similar.
for %%a in (*.txt) do find "string" < %%a >> newfile
=====================================
If at first you don't succeed, you're about average.M2
Thanks! That worked just fine. Is it possible to attach the filename of where the string was found into the 'newfile'?
Is it DOS or W2K?
=====================================
If at first you don't succeed, you're about average.M2
Its in DOS. Thanks again mate
@echo off > newfile
for %%a in (*.txt) do @echo %%a =========== >> newfile & find "string" < %%a >> newfile[that's 2 lines]
=====================================
If at first you don't succeed, you're about average.M2
Hi M2, Thanks again. But it doesnt work. It doesnt copy the file name of the file that contains the string into the newfile.
Post a sample of the directory you're running it in.
=====================================
If at first you don't succeed, you're about average.M2
for example: Folder: C:\temp. In it contains 1.txt and 2.txt. The string "happy" is contained only in 1.txt. The batch file does a search on both the txt files and when it finds the string "happy", it will copy the entire line into "newfile". If the string is not found, move to next file.
I'm stumped. Do a VER and report exact OS.
=====================================
If at first you don't succeed, you're about average.M2
Microsoft Windows 2000 [Version 5.00.2195] Based on the latest code that was given, it still doesn't copy the filename along with the line from which the string was found.
I tried manipulating your code a bit with whatever basic understanding I have of DOS and came up with this:
@echo off > Block.txt
for %%a in (*.fmt) do @echo %%a Block.txt & find "Blocked" < %%a >> Block.txt & @echo %%a >> Block.txt(2 lines)
Thing is, this code copies the filename, regardless if the string was found or not.
w2000 is not DOS. The code in #8 works in w2000.
=====================================
If at first you don't succeed, you're about average.M2
hey mate. my bad. it works. forgot to put the >> in the last line. Thanks!
