Search found 1042 matches

by jeb
02 Dec 2010 03:29
Forum: DOS Batch Forum
Topic: Batch File to Replace String in Text File
Replies: 8
Views: 36649

Re: Batch File to Replace String in Text File

@orange_batch sorry but the code fails with the sample input file, because it strips the leading ]] in line 6. The delims=] doesn't work if ] could be also the first char in the input file. You could changed it to line=!line:*]=! to remove the beginning. @echo off setlocal DisableDelayedExpansion se...
by jeb
01 Dec 2010 14:08
Forum: DOS Batch Forum
Topic: Batch File to Replace String in Text File
Replies: 8
Views: 36649

Re: Batch File to Replace String in Text File

Hi lostpenan, this batch should work (secure also with < and > ) @echo off setlocal DisableDelayedExpansion set "search=FILEPATH" set "replace=C:\temp" del output.txt for /F "delims=" %%a in (xml.tmp) DO ( set line=%%a setlocal EnableDelayedExpansion >> output.txt echo(...
by jeb
30 Nov 2010 16:21
Forum: DOS Batch Forum
Topic: need help passing a variable
Replies: 11
Views: 13408

Re: need help passing a variable

Hi, you can test with this snippet, it should work @echo off setlocal set var1=one set var2=this is two call :swapvars var1 var2 echo var1=%var1% echo var2=%var2% goto :eof :swapvars setlocal call set "x=%%%~2%%" endlocal&call set "%~2=%%%~1%%"&set "%~1=%x%" exi...
by jeb
26 Nov 2010 16:07
Forum: DOS Batch Forum
Topic: How to replace "=","*", ":" in a variable
Replies: 34
Views: 288683

Re: How to replace "=","*", ":" in a variable

Good thought, I suppose this way could be successful. But two problems. 1. As long as DelayedExpansion is active over a for loop, you got problems with exclamation marks and carets. set "Teststring=caret^ and !" the "!" and the "^" are removed in the %%y expansion. This...
by jeb
26 Nov 2010 11:46
Forum: DOS Batch Forum
Topic: An example of extreme dynamic variable nesting.
Replies: 8
Views: 10407

Re: An example of extreme dynamic variable nesting.

Yes, it works if you put and escape the content in a variable. But it is not possible to build a string with special characters and make a call, the expansion have to be on the last call level. All these variants will fail call echo 0 one & two call echo 1 one ^& two call echo 2 one ^^& ...
by jeb
26 Nov 2010 04:08
Forum: DOS Batch Forum
Topic: An example of extreme dynamic variable nesting.
Replies: 8
Views: 10407

Re: An example of extreme dynamic variable nesting.

Ok, nice A call is time intensive (nearly 20times slower than delayed expansion), and it have some nice unexpected side effects. And do you can explain this @echo off setlocal EnableDelayedExpansion set "singleCaret=^" set "^=One caret" set "^^=Two carets" call echo 1: ...
by jeb
25 Nov 2010 06:13
Forum: DOS Batch Forum
Topic: When I cancel the batch via Ctrl+C The first row deleted
Replies: 2
Views: 3901

Re: When I cancel the batch via Ctrl+C The first row deleted

Hi karzer,

test the content of IP

Code: Select all

@echo off
set "IP="
set /p IP=
if "%IP%"=="" (
  echo Nothing entered or CTRL-Break
  goto :eof
)
FOR /L %%G IN (0,1,255) DO route delete %IP%.%%G
exit


jeb
by jeb
25 Nov 2010 06:07
Forum: DOS Batch Forum
Topic: How to replace "=","*", ":" in a variable
Replies: 34
Views: 288683

How to replace "=","*", ":" in a variable

Hi, amel27 introduced the problem of replacing "=", ":", "*" or "~" signs. It is obvious that replacing an equal is tricky, because it is also the delim for the part of original to replace text. So this doesn't work ( try to replace "=" with "#&...
by jeb
25 Nov 2010 06:01
Forum: DOS Batch Forum
Topic: How Use special | > < = & in variable Dos
Replies: 7
Views: 8409

Re: How Use special | > < = & in variable Dos

Ok replacing the "=" and ":" are also interesting issues (in my humble opinion).

Therefore, I open a new thread for it.

jeb
by jeb
24 Nov 2010 18:08
Forum: DOS Batch Forum
Topic: How Use special | > < = & in variable Dos
Replies: 7
Views: 8409

Re: How Use special | > < = & in variable Dos

Ok, there is a solution without delayed expansion, but it's much more complicated. And a real solution should solve all variants of your tests with only one code. I suppose a test case could be something like @echo off setlocal DisableDelayedExpansion FOR /F "delims=" %%a in (file_inp.txt)...
by jeb
24 Nov 2010 13:11
Forum: DOS Batch Forum
Topic: how to pass/read unicode char on command line/batch script
Replies: 12
Views: 31621

Re: how to pass/read unicode char on command line/batch scri

Hi, As I just discovered, you can write and read properly a UTF-8 file under codepage 65001, but as usual for is unable to see the unicode from type. Strangely, you can paste unicode into for fine though. Redirection doesn't work either... type must do some kind of look-up when doing unicode that fo...
by jeb
24 Nov 2010 11:07
Forum: DOS Batch Forum
Topic: How Use special | > < = & in variable Dos
Replies: 7
Views: 8409

Re: How Use special | > < = & in variable Dos

Hi darioit, This should work. @echo off setlocal DisableDelayedExpansion FOR /F "delims=" %%a in (file_inp.txt) do set "name=%%a" &call :procName goto:eof :procName setlocal EnableDelayedExpansion >> file_out.txt echo(!name! endlocal goto :eof Your problem was that after the ...
by jeb
23 Nov 2010 02:10
Forum: DOS Batch Forum
Topic: How to manipulate a "%%x"- type string read from a file?
Replies: 6
Views: 6759

Re: How to manipulate a "%%x"- type string read from a file?

In this example it is easy with toggling the delayed expansion, because the content is only echo'd.

But if you want to keep the value(s), it's quite more tricky, because the endlocal destroys the variables again.

jeb
by jeb
22 Nov 2010 16:06
Forum: DOS Batch Forum
Topic: How to manipulate a "%%x"- type string read from a file?
Replies: 6
Views: 6759

Re: How to manipulate a "%%x"- type string read from a file?

Hi vltreude, as Masiosare and orange_batch explained, the delayed expansion is a good way to solve your problem. But there could be problems with carets "^" and exclamation marks "!" If in your text are these characters, you will lose the exclamation marks and, if at least one ex...
by jeb
21 Nov 2010 05:41
Forum: DOS Batch Forum
Topic: Doing a random true/false =FIXED=
Replies: 2
Views: 3179

Re: Doing a random true/false =FIXED=

Hi Azrooh,

this should work

Code: Select all

set /a r=%random% %% 2
if %r%==1 (echo true) else (echo false)


hope it helps