| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
Windows Bat: Find line in file
|
Original Message
|
Name: pednoy
Date: November 21, 2004 at 22:50:03 Pacific
Subject: Windows Bat: Find line in fileOS: Win 2000CPU/Ram: Xeon 1g |
Comment: Dear, I have some problem about batch programming, I have to write batch that find line "Server (PID = 1856) Ready" or "Server Mode 2 (PID = 2453) Ready" in file and assign 1856 or 2453 to a variable. Note that a line can be at anywhere in file. 1 file has only 1 line. How can i do all of this with windows bat script? Or i need some execute program to help. If anyone can help me it is a pleasure. Thank you very much. Pednoy
Report Offensive Message For Removal
|
|
Response Number 2
|
Name: pednoy
Date: November 23, 2004 at 01:24:21 Pacific
|
Reply: (edit)Sorry for unclear information. There are many files that generated from my system. Each file will contain many lines and will contain one of two lines I mentioned above. Unfortunately that I can not know exactly where "Server (PID = 1856) Ready" or "Server Mode 2 (PID = 2453) Ready" will be at which line number. Because the files are generate from legacy system and has variety name. For detecting file name and read it, I can do now. Next step is to retrieve number after "PID =" to assign to a variable. Is there anyway to do this?
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: Mechanix2Go
Date: November 23, 2004 at 02:17:14 Pacific
|
Reply: (edit)Hi, This should do it: ::## @echo off set MYVar= find "Server (PID = 1856) Ready" filename if errorlevel 1 goto next set MYVar=1856 goto end :next find "Server Mode 2 (PID = 2453) Ready" filename if errorlevel 1 goto end set MYVar=2453 :end M2
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: pednoy
Date: November 24, 2004 at 16:58:03 Pacific
|
Reply: (edit)Thanks Mechanix2Go. You gave me many ideas. How about if it is possible to find "(PID =" and move cursor to after its position. then read number after that until find ")".Because number is process number and it can vary. Thanks for you kindly help
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: Mechanix2Go
Date: November 24, 2004 at 23:56:06 Pacific
|
Reply: (edit)pednoy, This should do it: @echo off :: This is the world-famous PID setter bat by Computer Mechanix :: http://www.Golden-Triangle.com ::
set MYvar= set MYvar2= set PID= set Mode2PID= find "Server Mode 2 (PID" <filename>mode2 find "Server (PID" <filename>NOmode2 set /p MYvar2=<mode2 set /p MYvar=<NOmode2 set PID=%MYvar:~15,4% set Mode2PID=%MYvar2:~22,4% echo PID= %PID% echo Mode2PID= %Mode2PID% M2
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home