Find and Replace

May 27, 2010 at 14:57:45
Specs: Windows XP
I need help to build a DOS bach to make find
and replace strings based on a list separated
by a comma. It uses characters like: & < > ç
ã õ ... for both (find and replace) and seriously
i'm stucked.
With vba it doesn't work.

Please help me!

See More: Find and Replace

Report •

May 28, 2010 at 17:26:55
if you are not averse to vbscript:
dim fso,y,z
set fso=createobject("scripting.filesystemobject")
const forreading=1, forwriting=2, forappending=8
set tran=fso.opentextfile("tran",forreading)
if not tran.atendofstream then dofile=tran.readline else dofile=wscript.arguments(0)
wscript.echo "Processing translation of: "&dofile&" to output 'newfile'"
set infile=fso.opentextfile(dofile,forreading)
set ofile=fso.createtextfile("newfile",forwriting)
do while not infile.atendofstream
for i=0 to ubound(y)
ofile.writeline x
'---------- end script
you can prob'ly see how it works, but:
TRAN is your translate file, comma-separated. The
to-be-replaced-items are line one, the replacements are line two.
The optional third line is the filename, or you can put it on the commandline:
cscript tran.vbs testfile.txt
if you ARE averse, here's a DEBUG version, but the input is not comma-sep and is specified as 2-digit hexadecimal, like: 414243
(equivalent to "A","B","C")
(replacement only, not insertion or deletion!)
:: DEBUG-driven simple char. repalcement tool
@echo off>deb & setlocal enabledelayedexpansion
set c=0
for /f %%a in (tran) do (
set /a c+=1
set yy=0
set xx=%%a
call :two
set xx!c!=%cc%

(echo f100,ffff,ff
echo L
echo s100,ffff,%xx1%
echo q) | debug %1 > deb2
(for /f "skip=3 tokens=1-2 delims=:" %%a in (deb2) do (
if "%%b" neq "" (echo e%%b%xx2%) else (echo w & echo q)
)) > deb
debug %1 < deb2 > nul
goto :eof

if c>2 goto :eof
set aa=!xx:~%yy%,2!
set /a yy+=2
if "%aa%" equ "" goto :eof
set cc=%cc% %aa%
goto :two

Report •
Related Solutions

Ask Question