使用批处理文件从CSV文件中删除第2行

时间:2017-02-10 18:14:21

标签: csv batch-file

我只需要使用批处理文件从csv文件中删除第二行。它总是将成为第二行,尽管文本可能不同。

我一直在寻找答案,但似乎它们总是比我想做的更复杂

2 个答案:

答案 0 :(得分:4)

@echo off
setlocal EnableDelayedExpansion

rem Read lines from input.csv
< input.csv (

   rem Read and copy the first line
   set /P "line="
   echo(!line!

   rem Just read the second line
   set /P "line="

   rem Copy the rest of lines
   findstr "^"

) > output.csv

答案 1 :(得分:2)

@echo off & setlocal

>outfile.csv (
    for /f "tokens=1* delims=:" %%I in (
        'findstr /n "^" infile.csv ^| findstr /v "^2:"'
    ) do echo(%%J
)

要遵循此脚本的逻辑,请从里到外阅读。第一个findstr将读取infile.csv并在每行前面添加行号。管道式第二findstr命令将排除以2:开头的所有行。外部for /F将删除前面的行号。整个事情被转移到outfile.csv

相关问题