如何創建批處理文件,以從CSV文件中刪除從特定列雙引號如何創建批處理文件,以從CSV文件中刪除從特定列雙引號
輸入CSV文件:
"DocumentType","Company","Division","SeasonYear","Style"
"832","XYZ","S17","2017","S"
"832","XYZ","S17","2017","M"
我想從列1中刪除雙引號,其中值將在標題(第一條記錄)中爲DocumentType,對於其餘記錄則爲832。
預期的結果應該是:
DocumentType,"Company","Division","SeasonYear","Style"
832,"XYZ","S17","2017","S"
832,"XYZ","S17","2017","M"
我試着用下面的批處理腳本,但它取代所有雙引號中的文件。
@echo off
setlocal EnableDelayedExpansion
set FileIn=out.csv
set FileOut=in2.csv
(
for /F "usebackq tokens=*" %%A in ("%FileIn%") do (
set Line=%%A
set Line=!Line:"=!
for /L %%B in (1,1,20) do (
set Line=!Line: ,=,!
set Line=!Line:, =,!
)
echo.!Line!
)
) > "%FileOut%"
請指教。
這對於幫助 這適用於第一個記錄。但是我想對輸入文件 –
中的所有行重複此操作。由於您現在有工作解決方案,因此我建議您決定將哪個作爲解決方案,並將其標記爲您接受的答案。 – Compo
簡單:'(for/F「tokens = 1 * delims =,」%(in input.csv)do @echo%〜a,%b)> output.csv'(從命令行) – Aacini