Computing.Net > Forums > Programming > Extracting variable from txt file?

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.

Extracting variable from txt file?

Reply to Message Icon

Name: deirdredm
Date: August 5, 2004 at 10:08:05 Pacific
OS: Win XP Pro
CPU/Ram: Athlon 2.4 ghz, 256mb DDR
Comment:

I have a txt file containing one line of text which looks something like this : " JDOE <03> UNIQUE 10.123.10.247 362" - only without then inverted commas. The various pieces of text can vary, but will always follow the same format. I want to extract the IP address to a variable in a batch file - any ideas on how I can do it? Is this possible?? thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 5, 2004 at 11:57:05 Pacific
Reply:

Hi Deirdre,

There must be a way in XP with the cmd extensions, tokens and all that. But it's beyond me.

Here's what I've got. It uses two small utilities, CHANGE & PREFIX.

####
@echo off > quit.bat
@echo echo %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >> quit.bat

echo.
echo This is the world famous %0.bat
echo.
echo copyright 2004 ThaiGuides.com All rights reserved
echo.
echo Free for private use. Others email: Consult@ThaiGuides.com
echo.
echo built and tested on windoze 2000; may act funny on other versions
echo.
echo. Purpose - get ip from file into var

::*********************************************************************

if %1'==' quit which file?

change %1 32 13,10
echo.
echo.
find "." < %1 > ##
prefix "set MYvar=" <##> IPset.bat
call IPset

echo MYvar=%MYvar%
###

Note: It wraps around in this little forum editor window, but I think you can figure it out.



0

Response Number 2
Name: deirdredm
Date: August 5, 2004 at 14:45:51 Pacific
Reply:

Thanks, Mechanix, gives me another avenue to explore.. Dos is new to me, I'm afraid, I'm more used to unix and I wasn't very good at shell programming in that either! ;)


0

Response Number 3
Name: dtech10
Date: August 5, 2004 at 15:03:18 Pacific
Reply:

Hi
This might help if IP address the same
number of characters.

@echo on
rem set IP var to file contents
set /p IP=<IP.txt
rem Get Last (Rightmost) 17 characters
set IPAdr=%IP:~-17%
echo %IPAdr%


0

Response Number 4
Name: Don Arnett
Date: August 5, 2004 at 17:01:36 Pacific
Reply:

If you are used to Unix and are going to be doing a lot of this type of thing, it might be worth downloading 'cygwin'. It is a shell that let's you run unix commands on windows PCs.

I use it all of the time on my windows boxes.

Just google for it. IT will be easy to find.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Working with rs232 in Vis... batch files



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: Extracting variable from txt file?

Extracting data out from txt file www.computing.net/answers/programming/extracting-data-out-from-txt-file-/20329.html

Extract Values from a txt file www.computing.net/answers/programming/extract-values-from-a-txt-file/17728.html

Read lines from .txt file in DOS? www.computing.net/answers/programming/read-lines-from-txt-file-in-dos/15219.html