Computing.Net > Forums > Programming > Find and replace a symbol in many t

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Find and replace a symbol in many t

Reply to Message Icon

Name: mikhail
Date: November 8, 2007 at 16:17:10 Pacific
OS: 2003
CPU/Ram: dual xeon 4gig ram
Product: HP DL380
Comment:

Hi, Can someone help. I need a way to search through many text files to find an "Ã" and replace it with a "~". Or at least search through many text files and alert me if an à exists. Thanks in advance. Mike



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 8, 2007 at 17:31:54 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

del *.new

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
set name=%%~Na
for /f "tokens=* delims= " %%t in (%%a) do (
set str=%%t
set str=!str:A=~!
echo !str!>> !name!.new
)
)



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

M2



0

Response Number 2
Name: Mechanix2Go
Date: November 8, 2007 at 18:12:44 Pacific
Reply:

OOPS not so fast

That replaces 'a' as well as 'A'. Probably not what you want.

Needs more work.


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

M2



0

Response Number 3
Name: Razor2.3
Date: November 9, 2007 at 08:48:11 Pacific
Reply:

Here's a VBScript that'll do it:

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oRegEx = New RegExp
oRegEx.Global = True
oRegEx.Pattern = InputBox("Replace what?", "Replace Text", "Ã")
sRep = InputBox("With what?", "Substitute Text", "~")

If Len(oRegEx.Pattern) = 0 Or Len(sRep) = 0 Then _
WScript.Quit

For Each oFile In oFSO.GetFolder(".").Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "txt" Then
sFile = oFile.OpenAsTextStream().ReadAll
oFile.OpenAsTextStream(2).Write oRegEx.Replace(sFile, sRep)
End If
Next
WScript.Echo "Done"


0
Reply to Message Icon

Related Posts

See More


Batch file for mtu settin... VBS and Perl



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: Find and replace a symbol in many t

Find and replace a string in a file www.computing.net/answers/programming/find-and-replace-a-string-in-a-file/19034.html

find and replace string in a file www.computing.net/answers/programming/find-and-replace-string-in-a-file/19987.html

find and replace ultra with extra in files www.computing.net/answers/programming/find-and-replace-ultra-with-extra-in-files/19290.html