bat批处理提取多个文本文件的倒数第二行并输出保存到ok.txt。诚心感谢帮忙。谢谢。

bat批处理提取多个文本文件的倒数第二行并输出保存到ok.txt。诚心感谢帮忙。谢谢。

第1个回答  2013-06-30
@echo off
set "fn=ok.txt"
echo 正在提取...
(for /f "delims=" %%i in ('dir/b/a-d *.txt^|findstr/ivx "%fn:.=\.%"')do (
  >con echo %%i
  set "#="
  for /f %%a in ('type "%%i"^|find /v /c ""')do if %%a gtr 1 set/a "#=%%a-1"
  if defined # call :yky "%%~i"
))>"%fn%"
pause&goto :eof
:yky
for /f "tokens=1* delims=:" %%q in ('findstr/n ".*" %1^|findstr/b "%#%:"')do echo.%%r

本回答被网友采纳
第2个回答  2013-06-30
@echo off&setlocal enabledelayedexpansion
(for /f "delims=" %%i in ('dir /b/a-d *.txt^|findstr /ivx "ok\.txt"') do (
    sort /+10000 "%%i" >tmp
    (for /l %%a in (1,1,2) do set str=&set/p str=)<tmp>nul
    echo,!str!
))>ok.txt
del tmp&start ok.txt

本回答被提问者采纳
相似回答
大家正在搜