Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
In a dos batch I am searching one txt file line by line. How can I find line that starts with some string?
So I need something like:
if line starts with "string" do (...) in dos batch!Thx for help!

First you need something like a regex tool.
Search for xgrep.
=====================================
If at first you don't succeed, you're about average.M2

findstr /B /C:"string" File.txt > nul if not ErrorLevel 1 ( Your Commands )
This is NOT DOS but NT batch; see the above thread for some hints.

I need to find string inside other string(not inside file)!
I am reading file with:
for /f "eol= tokens=* delims= usebackq" %%a in (D:\test_promweb.log) do (
i need something like:
findstr /B /C:"VMtriggers" "%%a" > nul ....Is it possible to find string inside other string or to compare 2 strings?

"In a dos batch I am searching one txt file line by line. How can I find line that starts with some string?"
English is not my mother tongue as I am Italian, but I'm sure to have correctly understood your question.Anyway from your post #3 I suggest you try
findstr /B /C:"C:\VMtriggers" "D:\test_promweb.log" > nul if not ErrorLevel 1 ( Your Commands )
as your For /F loop does nothing else than to read the file and makes cumbersome an easy operation.Take a look at the thread above this one as coding inside an IF may be tricky for not trained people.

I am reading from file test_promweb.log with:
for /f "eol= tokens=* delims= usebackq" %%a in (D:\test_promweb.log)Lets say my test_promweb.log looks like:
line 1 - C:\VMtriggers\Preb_script>pcli RenameLabel
line 2 - C:\VMtriggers\Preb_script>goto end
line 3 - C:\VMtriggers\Preb_script>del
line 4 - fri 19.06.2009
line 5 - C:\VMtriggers\Preb_script>if
line 6 - 0 File(s) copiedAs I said I am reading line by line.
I am trying to find out if line 1, line 2, line 3.... line 100 are starting with string "C:\VMtriggers"!example - I have line "C:\VMtriggers\Preb_script>del", so I am trying to find out if I can find "C:\VMtriggers" in "C:\VMtriggers\Preb_script>del"
I hope u will understand my problem now :)

you are the one not understanding what IVO posted. the findstr command uses an internal "for loop" (if you want to call it that way) to loop through files , so in fact, you don't need to use your own for loop (just for this case). as for searching within a string, that's what findstr does. It goes over the lines in the file and grab your string according to parameters you give it.

![]() |
![]() |
![]() |

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