使用批处理删除csv文件上的重复项

时间:2018-12-05 22:30:20

标签: windows batch-file

我有下一个代码,效果很好,但是,如果我在任何字符如!的末尾都带有字符,则将擦除所有内容,或仅保留奇怪的数据。 有什么办法可以忽略字符

  

i

为避免此问题?

我要删除第二列的重复数字

输入Csv文件的示例。

"Hello","0001","abc","123"
"hello","0002","abc","123"
"heLLo","0001","abc","123"
"hello!","0003","abc","123"

预期的输出文件。

"Hello","0001","abc","123"
"hello","0002","abc","123"

该行已删除,因为在所有行上重复的数字 0001

"hello!","0003","abc","123"

代码的错误结果是由!字符。

"hello03"

代码

    @echo off
setlocal EnableDelayedExpansion
set src=Clean\File.csv
set line=
(for /F "delims=" %%L in ('sort %src%') do (
   if not ~!line!~ == ~%%L~ echo %%L
   set line=%%L
)) > "%Final.csv

0 个答案:

没有答案