ampersand problem find in a row

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

ampersand problem find in a row

#1 Post by darioit » 12 Aug 2010 04:13

Hello again,

this batch really works well, but when in a row there's some "&" ampersand simbol, this is interpreted as a command and divide the outpur result in two line also I got this errors sometimes

Numero non valido. Le costanti numeriche sono decimali (17),
esadecimali (0x11) o ottali (021).
"sleep" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.
Numero non valido. Le costanti numeriche sono decimali (17),
esadecimali (0x11) o ottali (021).


I try to use "%name%" and works fine, but I don't want "" in a new file

Any idea? Thanks in advance
Best

Code: Select all

@echo off &setlocal
pushd "E:\bat\Temp"

for /f "delims=" %%a in (fileinput.txt) do set "name=%%a"&call :procName

popd
goto :eof

:procName
if "%name:~2,2%"=="00" (
  for /f "usebackq tokens=1,2 delims=;" %%a in ("%~dp0Table2.txt") do if "%name:~4,4%"=="%%a" (
    set "newCode1=%%b"
    for /f "usebackq tokens=1,2 delims=;" %%c in ("%~dp0Table1.txt") do if "%name:~0,2%"=="%%c" (
      set "newCode2=%%d"
      goto break_loop
    )
  )
)

:break_loop
>> "ADDRESS.%newCode1%.%newCode2%" ECHO %name%
goto :eof

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ampersand problem find in a row

#2 Post by aGerman » 12 Aug 2010 07:19

Escape it this way:

Code: Select all

:break_loop
set "name=%name:&=^&%"
>> "ADDRESS.%newCode1%.%newCode2%" ECHO %name%
goto :eof


Regards
aGerman

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: ampersand problem find in a row

#3 Post by darioit » 12 Aug 2010 08:04

Thanks aGerman, you're the best, but why the suggestion on this site doesn't work?

http://www.dostips.com/DtTipsStringOper ... veBothEnds
and also this
http://www.dostips.com/DtTipsStringOper ... TrimQuotes

Thanks
Dario

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ampersand problem find in a row

#4 Post by aGerman » 12 Aug 2010 08:14

Hmm, works for me. In case you have special characters like &<>| in the variable value it will probably not work. Tell me an example where it doesn't work for you.

Regards
aGerman

Post Reply