我只需要使用批处理文件从csv文件中删除第二行。它总是将成为第二行,尽管文本可能不同。
我一直在寻找答案,但似乎它们总是比我想做的更复杂
答案 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
。