Set word from text file as variable

July 9, 2009 at 04:55:03
Specs: Windows XP / Vista
I have a text file (User.ini) with the following information:

CUSTOMER_NUMBER = 1001
FIRST_NAME = Francisca
MIDDLE_NAME =
LAST_NAME = Carstens

I need to extract the customer number "1001" and set it as a variable in my batch file. The number might be anything from 4 to 6 characters long. There might also be a space missing after the "="
(CUSTOMER_NUMBER =269367).

I've tried about everything I could find in the faq's, but as I'm not an advanced programmer I'm really struggling to understand what I need to do. Your help will be much appreciated.


See More: Set word from text file as variable

Report •


#1
July 9, 2009 at 05:05:18
When I do this:

set /p VAR=<User.ini
echo %VAR%

It echos back this:
■C

I think it's got something to do with the code or something of the ini file. Because if I create a new ini file by manually typing the info in, it works and echos:
CUSTOMER_NUMBER = 1001


Report •

#2
July 9, 2009 at 05:49:46
ok... got it working sort of

iconv -f UTF-16LE -t UTF-8 User.ini > User_output.txt
set /p VAR=<User_output.txt

> usermessage.vbs ECHO WScript.Echo^( "%VAR%"^)
WSCRIPT.EXE usermessage.vbs
DEL usermessage.vbs
iconv -f UTF-8 -t UTF-16LE User_output.txt > User.ini
exit

but the variable in the vbs file is passed like this:
CUSTOMER_NUMBER = 1001
So it looks a bit odd on the pop-up.

I need to try extracting all characters after the "=", but have no clue.


Report •

#3
July 9, 2009 at 06:19:57
@echo off & setLocal enableDELAYedexpansion

for /f "tokens=2 delims==" %%a in (user.ini) do (
set var=%%a
goto :done
)

:done
echo !var!


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

M2


Report •

Related Solutions

#4
July 9, 2009 at 06:59:59
Thanx!
Still got a problem with the format though. I need to run this file on customers' pc's, and realised that i can't use iconv on their machines..
Any ideas?

Report •

#5
July 9, 2009 at 07:14:10
No idea what iconv is.


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

M2


Report •


Ask Question