Hi together,
I really love this forum and hope I can find a solution.
I already tried to find something in the search, but I wasn't able to get a solution.
There is a .csv file with a changing order number like 68688-74747-473.
We need to replace the "-" into a "/" - but only in the column 1.
Other columns can also contain the character "-" (e.g. phone number or house number), they don't should be changed.
Maybe I'm too silly for that I hope someone can help me.
Regards
Thomas
Replace a specific character in CSV
Moderator: DosItHelp
Re: Replace a specific character in CSV
Pretty similar: viewtopic.php?f=3&t=10035
Steffen
Code: Select all
@if (0)==(0) echo off &setlocal
set "infile=test.csv"
set "outfile=out.csv"
set "separator=;"
cscript //nologo //e:jscript "%~fs0" "%infile%" "%outfile%" "%separator%"
goto :eof @end
var oFSO = new ActiveXObject('Scripting.FileSystemObject'),
oInFile = oFSO.OpenTextFile(WScript.Arguments(0)),
oOutFile = oFSO.OpenTextFile(WScript.Arguments(1), 2, true),
delim = WScript.Arguments(2),
line = '',
arr = [],
idx = 0;
while (!oInFile.AtEndOfStream) {
line = oInFile.ReadLine();
arr = line.split(delim);
arr[0] = arr[0].replace(/-/g, "/");
oOutFile.WriteLine(arr.join(delim));
}
oInFile.Close();
oOutFile.Close();
Re: Replace a specific character in CSV
Code: Select all
@echo off
setlocal EnableDelayedExpansion
(for /F "tokens=1* delims=," %%a in (input.txt) do (
set "col1=%%a"
echo !col1:-=/!,%%b
)) > output.txt
Code: Select all
68688-74747-473, Col-num-2, Col-num-3
88686-47474-374, Num-col-2, Num-col-3
Code: Select all
68688/74747/473, Col-num-2, Col-num-3
88686/47474/374, Num-col-2, Num-col-3
-
- Posts: 2
- Joined: 19 Apr 2021 15:16
Re: Replace a specific character in CSV
Thank you Steffen and Antonio!!!!! You are the best!