Computing.Net > Forums > Programming > Replacing text in files BAT file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Replacing text in files BAT file

Reply to Message Icon

Name: Podde
Date: August 10, 2008 at 10:04:50 Pacific
OS: XP
CPU/Ram: 2,6/4096
Product: Intel
Comment:

I have been reading all the posts and tips here about replacing text in files. However, neither of them works for me.

I have a regfile containg a lot of "123xyz".
I want to replace them within a BAT with new text. The new text comes as a variable %var%, but also resides in a plain textfile.

The variable iteself always have the format of "HKEY_USERS\S-1-2-34-5678901234-1234567890-1234567890-1003" but from time to time with different numbers.

So far I have tried sed, change, sbs2, fart, mtr and munge. Some are close to working. Anyone have a solution?



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: August 10, 2008 at 18:09:33 Pacific
Reply:

then show your code.


0

Response Number 2
Name: Mechanix2Go
Date: August 10, 2008 at 22:43:57 Pacific
Reply:

No reason CHANGE.exe won't do it. But here's the bat.

::=========================
@echo off > newfile
setLocal EnableDelayedExpansion

set /p new=<var.txt

for /f "tokens=* delims= " %%a in (somereg.txt) do (
set str=%%a
set str=!str:123xyz=%new%!
echo !str! >> newfile
)


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

M2


0

Response Number 3
Name: Podde
Date: August 11, 2008 at 11:17:48 Pacific
Reply:

Sorry for a beginner as me, but I can't manage to get this to work. Here is what my batch looks like;

@echo off
::=====================================
::Get Unique SID string
::=====================================
setlocal
REG QUERY HKU |Findstr /R "DEFAULT S-1-5-[0-9]*-[0-9-]*$" >> out.txt
type out.txt | find /v /i "DEFAULT" >sid.txt
del /q out.txt
ECHO EXIT|%COMSPEC%/KPROMPT E100'SET VAR='$_RCX$_8$_NFILE1.BAT$_W$_Q|DEBUG>NUL
TYPE sid.txt>>FILE1.BAT
CALL FILE1.BAT
DEL FILE1.BAT
copy in.org in.reg


::=====================================
::Replace 123xyz with %var% or from sid.txt in in.reg
::=====================================

regedit /s in.reg
start /w exec.exe
del in.reg
del sid.txt
endlocal
exit

It is a portable application that need some registry info at HKU before starting, therefore the regfile in.org, where the SID is changed to xyz123. The in.reg would be the file where xyz123 is changed to the SID from the actual computer.


0

Response Number 4
Name: Mechanix2Go
Date: August 11, 2008 at 12:32:42 Pacific
Reply:

I have no idea what's going on.


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

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Replacing text in files BAT file

Batch file to replace text in file www.computing.net/answers/programming/batch-file-to-replace-text-in-file/20070.html

Replace text in file www.computing.net/answers/programming/replace-text-in-file/19635.html

Replace text in file www.computing.net/answers/programming/replace-text-in-file/19657.html