我有一个文件,其中包含数千条记录管道,每个字段用引号括起来
"First Name"|"Last Name"|"address"|"City"|"State"|"Zip"
如何在 Windows 上编写批处理脚本来处理文件中的数千条记录?
每行都有一条记录,使其如下所示
First Name|Last Name|address|City|State|Zip
我有一个文件,其中包含数千条记录管道,每个字段用引号括起来
"First Name"|"Last Name"|"address"|"City"|"State"|"Zip"
如何在 Windows 上编写批处理脚本来处理文件中的数千条记录?
每行都有一条记录,使其如下所示
First Name|Last Name|address|City|State|Zip
下载 GnuSed 是一个选项:
@echo off
sed "s/\x22//g" "filein.txt" >"fileout.txt"
您也可以使用 VBS 脚本来做同样的事情。
A bit more stable than the (also good) solution of Peter.
It can also handle lines with exclamation marks, carets,
this uses the toggling of the delayed expansion, as set "line=%%i"
only works for all characters if delayed expansion is disabled, but for removing the quotes, the delayed expansion have to be enabled.
Lines beginning with ";" are normally removed by the default EOL-character, therefore I used a bit tricky construct to disable the EOL at all.
@echo off
setlocal DisableDelayedExpansion
(
FOR /f delims^=^ EOL^= %%i IN (pipedelims.txt) DO (
SET "line=%%i"
setlocal EnableDelayedExpansion
SET "line=!line:"=!"
ECHO(!line!
endlocal
)
) > outfile.txt
@ECHO OFF
SETLOCAL enabledelayedexpansion
DEL outfile.txt 2>nul
FOR /f "delims=" %%i IN (pipedelims.txt) DO (
SET line=%%i
SET line=!line:"=!
>>outfile.txt ECHO(!line!
)
应该为你做这项工作。