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.
String search batch help
Name: deanamiller Date: November 19, 2006 at 16:57:08 Pacific OS: NT 4.0 CPU/Ram: 2.0 Product: Dell
Comment:
I am trying to write simple batch file that will perform a "string" search in C:\textfile.txt then COPY some file to some folder. Should I not use FOR /F ? The below command works but always performs the DO command regardless if the string is found or not.
FOR /F "usebackq delims==" %i IN (`FIND /I "error" C:\logfile.log`) DO echo Error Found > D:\report.txt
Name: Shr0Om Date: November 20, 2006 at 00:43:12 Pacific
Reply:
You dont have to use a FOR loop. Try:
type "c:\logfile.log" |find "error" if not errorlevel 1 echo "Error found" >"d:\report.txt"
0
Response Number 2
Name: Mechanix2Go Date: November 20, 2006 at 03:54:22 Pacific
Reply:
Hi Shroom,
I agree; no need for FOR.
I'd prefer this as a first line:
find "error" < logfile.log > nul
===================================== If at first you don't succeed, you're about average.
M2
0
Response Number 3
Name: deanamiller Date: November 20, 2006 at 20:08:27 Pacific
Reply:
Thanks Shr00m I'm almost there but can I use a command rather than a > D\output.txt ? I need to copy a file rather than produce output. I was using > D\output.txt just to see if I could get the .bat to work hoping it would be simple to change. I tried XCOPY and COPY but that produced nothing useful.
0
Response Number 4
Name: Mechanix2Go Date: November 20, 2006 at 21:15:29 Pacific
Reply:
I assume you want to copy a file based on the result of the string search. If so, you need to know that FIND sets an errorlevel which you can use for decision making.
Summary: Batch Hi I am not able to extract a part of a string. I need Help i am using this expression set var1=%cd:~-%length%% where length is 10 but this is not working but when i use the following expressio...
Summary: I am trying to write a program that reads a file and prints each line of the file that contains a given string. Can anyone help me with this? ...
Summary: I have a file which is essentially of no specific format..but it has a string in it somewhere "-stringtolookfor stringvalue" and i need to write a batch script to look for this string, and save the va...