Dear all,
I have following problem:
I have a file (data.txt) and want to replace "," with "!".
e.g. data.txt = "abc,def,ghi,jkl,mno"
and I want to change data.txt to "abc!def!ghi!jkl!mno"
Is this possible?
Thank you in advance for your help, this is highly appreciated!
change a single character in a file
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Try this -- though it could have problems with additional special characters:
Code: Select all
@echo off
for /f "delims=" %%a in (file.txt) do call :process "%%~a"
ren file.txt file.old
ren file.new file.txt
goto :eof
:process
set line=%~1
echo.%line:,=!%>>file.new
goto :eof
Use biterscripting for automated file manipulation
This can be done with biterscripting easily. biterscripting will correctly handle all special characters in the file.
I will restate your requirements.
This is easy. If you have biterscripting, the following commands will do exactly what you require.
If you don't have biterscripting, you can get it free as follows.
Sen
I will restate your requirements.
You have a file data.txt. That has data of the following form.abc,def,ghi,jkl,mno
You want to replace each comma (,) with exclamation mark (!). As a result, the processed file will have the following form.abc!def!ghi!jkl!mno
This is easy. If you have biterscripting, the following commands will do exactly what you require.
Code: Select all
# Read data into a str variable.
var str data ; cat data.txt > $data
# Replace each comma (,) with exclaimation mark (!).
while ( { sen "^,^" $data } > 0)
sal "^,^" "!" $data
# Write data back to file
echo $data > data.txt
If you don't have biterscripting, you can get it free as follows.
- 1. Download and install biterscripting from http://www.biterscripting.com .
2. Install all sample scripts using the following command
Code: Select all
script "http://www.biterscripting.com/Download/SS_AllSamples.txt"
Sen