Computing.Net > Forums > Disk Operating System > Using DOS to search for string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Using DOS to search for string

Reply to Message Icon

Name: giggsy
Date: July 3, 2008 at 16:35:08 Pacific
OS: Win2K
CPU/Ram: Intel Centrino
Product: HP
Comment:

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.




Sponsored Link
Ads by Google

Response Number 1
Name: DAVEINCAPS
Date: July 3, 2008 at 18:27:09 Pacific
Reply:

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?


0

Response Number 2
Name: Mechanix2Go
Date: July 4, 2008 at 01:32:47 Pacific
Reply:

Hi Dan

Could be a bit tricky in DOS.

LOL


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: giggsy
Date: July 4, 2008 at 09:34:53 Pacific
Reply:

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.


0

Response Number 4
Name: Mechanix2Go
Date: July 4, 2008 at 10:52:25 Pacific
Reply:

for %%a in (*.txt) do find "string" < %%a >> newfile


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: giggsy
Date: July 4, 2008 at 14:36:40 Pacific
Reply:

Thanks! That worked just fine. Is it possible to attach the filename of where the string was found into the 'newfile'?


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: July 4, 2008 at 14:57:49 Pacific
Reply:

Is it DOS or W2K?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: giggsy
Date: July 4, 2008 at 15:20:54 Pacific
Reply:

Its in DOS. Thanks again mate


0

Response Number 8
Name: Mechanix2Go
Date: July 4, 2008 at 20:30:41 Pacific
Reply:

@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


0

Response Number 9
Name: giggsy
Date: July 5, 2008 at 22:24:59 Pacific
Reply:

Hi M2,

Thanks again. But it doesnt work. It doesnt copy the file name of the file that contains the string into the newfile.


0

Response Number 10
Name: Mechanix2Go
Date: July 6, 2008 at 05:14:00 Pacific
Reply:

Post a sample of the directory you're running it in.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: giggsy
Date: July 7, 2008 at 10:59:17 Pacific
Reply:

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.


0

Response Number 12
Name: Mechanix2Go
Date: July 7, 2008 at 11:30:29 Pacific
Reply:

I'm stumped.

Do a VER and report exact OS.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 13
Name: giggsy
Date: July 7, 2008 at 12:28:06 Pacific
Reply:

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.


0

Response Number 14
Name: Mechanix2Go
Date: July 7, 2008 at 22:56:28 Pacific
Reply:

w2000 is not DOS.

The code in #8 works in w2000.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 15
Name: giggsy
Date: July 8, 2008 at 17:15:44 Pacific
Reply:

hey mate. my bad. it works. forgot to put the >> in the last line. Thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Using DOS to search for string

Automatic substition of strings using dos programs www.computing.net/answers/dos/automatic-substition-of-strings-using-dos-programs/3787.html

Zipping files using Dos Commands. www.computing.net/answers/dos/zipping-files-using-dos-commands/10548.html

Find text using Dos Batch www.computing.net/answers/dos/find-text-using-dos-batch/12400.html