:::1:::
CMD with variable substitution:
@echo off
if exist outf.txt del outf.txt
findstr /n "\<*" "infile.txt" > temp._t
for /f "tokens=*" %%a in (temp._t) do set "b=%%a" & call :sub
del temp._t & goto :eof
:sub
set "b=%b:"=¬%"
set "b=%b:^=^^%"
set "b=%b:|=^|%"
set "b=%b:&=^&%"
set "b=%b:(=^(%"
set "b=%b:)=^)%"
set "b=%b:>=^>%"
set "b=%b:<=^<%"
set "b=%b:search=replace%"
set "b=%b:¬="%"
>>outf.txt call echo.%%b:*:=%%
:::2:::
CMD with edlin
@echo off
if exist 3_ del 3_
for /f "tokens=1 delims=:" %%a in ('findstr /n "\<*" "%1"') do set n=%%a
set /a n=n/23
<nul>0_ (set /p="1r%~2")
<nul>2_ (set /p="%~3")
>nul copy /a 0_ 1_
>nul copy /b 1_+2_ 3_
>>3_ echo.
>>3_ echo w
>>3_ echo 900a
for /l %%a in (1,1,%n%) do >>4_ type 3_
>>3_ type 4_
>>3_ echo e
>nul<3_ edlin %1
del *.bak
del *_
exit
:::3:::
CMD via .com file:
Asm Source:
0100 MOV SI,0080
0103 CLD
0104 CALL 01E3
0107 INC SI
0108 MOV [01F8],SI
010C CMP BYTE PTR [SI],22
010F JZ 0114
0111 INC SI
0112 JMP 010C
0114 MOV BYTE PTR [SI],00
0117 CALL 01E3
011A XOR CX,CX
011C MOV DI,0200
011F CALL 01D3
0122 CALL 01E3
0125 MOV [01FA],CX
0129 XOR CX,CX
012B MOV DI,0280
012E CALL 01D3
0131 JMP 0145
0133 CMP DX,5120
0137 JNZ 013F
0139 MOV AH,3E
013B INT 21
013D INT 20
013F SUB DX,5120
0143 JMP 0181
0145 MOV [01FC],CX
0149 MOV AX,716C
014C MOV BX,0002
014F MOV CX,0000
0152 MOV DX,0001
0155 MOV SI,[01F8]
0159 INT 21
015B JB 013D
015D MOV [01FE],AX
0160 MOV BX,[01FE]
0164 MOV DX,511F
0167 ADD DX,+01
016A MOV SI,DX
016C MOV CX,0001
016F MOV AH,3F
0171 INT 21
0173 CMP AX,0000
0176 JZ 0133
0178 CMP BYTE PTR [SI],0A
017B JNZ 0167
017D SUB DX,511F
0181 MOV BX,5120
0184 MOV AX,0300
0187 MOV SI,0200
018A MOV DI,BX
018C MOV CX,[01FA]
0190 REPZ
0191 CMPSB
0192 MOV DI,AX
0194 JZ 019E
0196 MOV SI,BX
0198 MOVSB
0199 INC AX
019A INC BX
019B DEC DX
019C JMP 01B1
019E MOV SI,0280
01A1 MOV CX,[01FC]
01A5 ADD AX,CX
01A7 ADD BX,[01FA]
01AB SUB DX,[01FA]
01AF REPZ
01B0 MOVSB
01B1 DX,[01FA]
01B5 0187
01B7 CX,DX
01B9 AX,CX
01BB MOV SI,BX
01BD REPZ
01BE MOVSB
01BF MOV BYTE PTR [DI],00
01C2 MOV SI,0300
01C5 MOV DL,[SI]
01C7 MOV AH,02
01C9 INT 21
01CB INC SI
01CC CMP BYTE PTR [SI],00
01CF JZ 0160
01D1 JMP 01C5
01D3 INC SI
01D4 LODSB
01D5 CMP AL,22
01D7 JNZ 01DF
01D9 CALL 01EA
01DC JNB 01DF
01DE RET
01DF STOSB
01E0 INC CX
01E1 JMP 01D4
01E3 INC SI
01E4 CMP BYTE PTR [SI],20
01E7 JZ 01E3
01E9 RET
01EA CLC
01EB CMP BYTE PTR [SI],20
01EE JZ 01F6
01F0 CMP BYTE PTR [SI],0D
01F3 JZ 01F6
01F5 RET
01F6 STC
01F7 RET
Ascii version obtained with laura fairhead's cm3.com
(http://lf.8k.com/TOOLS/CM3.HTM) :
echo `h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>#.com
echo fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZ$:QC;$BW>>#.com
echo iay~K?e=RK;2$]mY5MC_p}y$6IVsW}j/iaUyDsX6j$fFEY*yG?Eff_H?9\FK>>#.com
echo b4QQ3?RMd{A`j{+RDQR_7dt]Zmqz$vXNLN_1kdN~eJ$W4=7xjv)6Lbzc3$_Q>>#.com
echo sW$_M2~R7Lh*vz$VkbqJ2B9`+,=e;'(XM\J;e0;vMIB,CQQf+vHMypsS\$_$>>#.com
echo Aixs~)Gw?Ctz?rjsEQH.egz$v]l'7W,F3nwQnw.dd,yH.4oTxXsXTvwTChph>>#.com
echo 9}$:?MAbsZI'=Ux'`M@'MY=m:t0M_zzS$'Z7{_t'ra=m1m6MCLdzQNG*a(,A>>#.com
echo }TMAJFgg}p6UGHUS)$C4+K#>>#.com
#.com "infile.ext" "string1" "string2">"outfile.ext"
infile.ext, string1 e string2 between ""
:::4:::
VBScript:
Set fso=CreateObject("Scripting.FileSystemObject")
r="text.txt"
if fso.FileExists(r)=false then
wscript.Quit
end if
set f=fso.OpenTextFile(r,1)
s=f.ReadAll
n=replace(s,"search","replace",1,-1,0)
set f=fso.OpenTextFile(r,2)
f.Write n
f.Close
:::5:::
VBScript using CommonDialog:
Set fil = CreateObject("UserAccounts.CommonDialog")
fil.ShowOpen
Set fso=CreateObject("Scripting.FileSystemObject")
s=inputbox("String to find")
re=inputbox("Replace with "&s&" with:")
r=fil.FileName
if fso.FileExists(r)=false then
wscript.Quit
end if
set f=fso.OpenTextFile(r,1)
ss=f.ReadAll
n=replace(ss,s,re,1,-1,0)
set f=fso.OpenTextFile(r,2)
f.Write n
f.Close
:::6:::
VBScript with Internet Explorer:
Set objShell = CreateObject("Wscript.Shell")
On Error Resume Next
Err.Clear
Set objIE = CreateObject("InternetExplorer.Application")
If Err.Number <> 0 Then
Err.Clear
Msgbox "Internet Explorer is not installed.", 16, "Browser"
Wscript.Quit(1)
End If
On Error GoTo 0
fil = sf("C:\")
If fil = "" Then
Msgbox "No file selected", 16, "Browser"
Else
Set fso=CreateObject("Scripting.FileSystemObject")
s=inputbox("String to find:")
re=inputbox("Replace "&s&" with:")
r=fil
if fso.FileExists(r)=false then
wscript.Quit
end if
set f=fso.OpenTextFile(r,1)
ss=f.ReadAll
n=replace(ss,s,re,1,-1,0)
set f=fso.OpenTextFile(r,2)
f.Write n
f.Close
End If
Set objIE = Nothing
Set objShell = Nothing
Function sf(fsp)
With objIE
.Navigate("about:blank")
Do Until .ReadyState = 4
If Wscript.Version > 5 Then
Wscript.Sleep 100
End If
Loop
With .Document
.Write("<html><body><input id=file type=file></body></html>")
.all.file.focus
If Wscript.Version > 5 Then
objShell.SendKeys fsp & "{Tab}"
Wscript.Sleep 200
End If
.all.file.click
sf = .all.file.value
If sf = fsp Then
sf = ""
End If
End With
End With
End Function
:::7:::
CMD + VBScript:
a)
>_.vbs echo Wscript.StdOut.Write Replace(WScript.StdIn.ReadAll,Wscript.arguments(0), Wscript.arguments(1))
<infile.txt cscript /nologo _.vbs "search" "replace">outfile.txt
b)
To replace the character " :
>_.vbs echo q=chr(34)
>>_.vbs echo s="search string"
>>_.vbs echo r="replace string"
>>_.vbs echo Wscript.StdOut.Write Replace(WScript.StdIn.ReadAll,q^&s^&q,r)
<infile.txt cscript /nologo _.vbs >outfile.txt |
|