connie87 当前离线
列兵
WHY 当前离线
上校
@echo off setlocal enabledelayedexpansion (for /f "skip=1" %%i in ('findstr /n .* 1.txt') do ( set "s=" & set /p s= echo;!s! )) < 1.txt pause复制代码
TOP
yhcfsr 当前离线
中尉
@echo off rem 源目录 set "SrcDir=D:\test folder" rem 输出目录 set "OutDir=D:\result" for /f "delims=" %%a in ('dir /a-d/s/b "%SrcDir%\*.txt"') do ( setlocal enabledelayedexpansion for /f "delims=" %%b in ('type "%%a"') do set/a n+=1 (for /f "delims=" %%i in ('findstr /n ".*" "%%a"') do set/a x+=1&&if !n! gtr !x! ( set "var=%%i"&&set var=!var:*:=! echo;!var! ))>"%OutDir%\%%~nxa" endlocal )复制代码
@echo off for /f "delims=" %%i in ('findstr /n .* 1.txt') do ( if defined s ( setlocal enabledelayedexpansion echo;!s:*:=! endlocal ) set "s=%%i" ) pause复制代码
@echo off PowerShell "$arr = type 1.txt; $arr[0..($arr.Count-2)]" pause复制代码
屡败屡战 当前离线
二级士官
@echo off rem 源目录 set "SrcDir=D:\test" rem 输出目录 set "OutDir=D:\result" rem 需要忽略的行,倒数行用负数表示,如倒数第2行为-2,行号间用空格(或,;制表符等)隔离。 set "lines=5;-2;-4;10" for /f "delims=" %%a in ('dir /a-d/s/b "%SrcDir%\*.txt"') do ( setlocal enabledelayedexpansion rem 计算总行数 for /f "delims=" %%b in ('type "%%a"') do set/a n+=1 rem 计算忽略的行号 for %%c in (%lines%) do (if %%c lss 0 (set/a ln=!n!+%%c+1&&set "lns=!ln! !lns!") else (set "lns=%%c !lns!")) rem 处理文本,忽略指定行,输出结果 (for /f "delims=" %%i in ('findstr /n ".*" "%%a"') do set/a x+=1&&echo !x!|findstr /v /r "!lns!">nul&&( set "var=%%i"&&set var=!var:*:=! echo;!var! ))>"%OutDir%\%%~nxa" endlocal ) pause&exit复制代码