Computing.Net > Forums > Programming > Batch ,read a word after : in txt

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.

Batch ,read a word after : in txt

Reply to Message Icon

Name: sonali
Date: August 28, 2008 at 03:07:35 Pacific
OS: windowsxp
CPU/Ram: dell
Product: Microsoft
Comment:

Hi All,

I have a text file say, tmp.txt which is having an unique entry at the end of the file "Status:Running" or "Status:Stopped".

Now through a Batch ,I want to read the word after ":" in this file tmp.txt.
And then store that word into a varaible say ,"abc" and check condition,

If abc=="Running " goto :Run
and if abc =="Stopped" goto :Stop

Can anybody help me?
Thanks in advance.

Hi! i m new to batch programing. I want to make a batch file which will search for a particular string in a ini file and replace it with a another string .

Can anyone help me.
Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: August 28, 2008 at 03:54:24 Pacific
Reply:

I want to clarify a couple of things

1.You say you say it is a "unique" entry, will it be the only line that starts with "status:"?

2.You say "at the end of the file", would it always be in a fixed position like the last or second last line?

3.Is there any posibility that there will be anything else on the line after "status:*state*"?


0

Response Number 2
Name: Razor2.3
Date: August 28, 2008 at 04:36:34 Pacific
Reply:

FOR /F "tokens=2 delims=:" %%a IN ('find "Status" ^<tmp.txt') DO SET abc=%%a


0

Response Number 3
Name: Mechanix2Go
Date: August 28, 2008 at 09:56:21 Pacific
Reply:

Looks like Razor2.3 has it nailed.

Be careful with your use of spaces or you'll wind up tearing your hair out.

If abc=="Running " goto :Run
and if abc =="Stopped" goto :Stop

You don't want to copare *abc* you want to compare the VALUE.

if !abc!==blabla

Better yet:

goto :!abc!

:running
: do bla
goto :eof

:stopped
: do bla2


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

M2


0

Response Number 4
Name: sonali
Date: September 2, 2008 at 00:40:49 Pacific
Reply:

For making it more clear,
I want to read the String after "Status:" which will be always the last line of the file.

Hi! i m new to batch programing. I want to make a batch file which will search for a particular string in a ini file and replace it with a another string .

Can anyone help me.
Thanks in advance.


0

Response Number 5
Name: Mechanix2Go
Date: September 2, 2008 at 01:12:51 Pacific
Reply:

Does that pertain to this thread?


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

M2


0

Related Posts

See More



Response Number 6
Name: Judago
Date: September 2, 2008 at 03:23:04 Pacific
Reply:

I just hate using find....
On my computer the below is marginally faster than using find on a large text file (36880 lines, 3.8mb).

Only if I could get it into one line.....


SET LINECNT=0
FOR /F "SKIP=1" %%G IN (YOURTEXTFILE.TXT) DO SET /A LINECNT+=1
FOR /F "SKIP=%LINECNT% TOKENS=2 DELIMS=: " %%H IN (YOURTEXTFILE.TXT) DO SET YOURVAR=%%H

[Edit: I have a knack for overcomplicating things]


FOR /F "TOKENS=2 DELIMS=: " %%H IN (YOURTEXTFILE.TXT) DO SET YOURVAR=%%H


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 Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch ,read a word after : in txt

read a text file in assembly www.computing.net/answers/programming/read-a-text-file-in-assembly/17267.html

open a new word document in vb.net www.computing.net/answers/programming/open-a-new-word-document-in-vbnet/19002.html

Read a MAILBOX through ASP www.computing.net/answers/programming/read-a-mailbox-through-asp/7217.html