我想修剪顶部和底部的文本文件。 说出文本文件是否包含90行。我想删除顶部x行和底部y行并更新文件。 (即只留下范围X + 1至Y-1。 因此,我到打算写一个批处理文件并运行它如下。通过批处理文件修剪文本文件
trimmer.bat file1.txt 2 8
此代码下面有以下限制 (a)中的文件打开/修改两次 (二)修剪范围内的空行(我不希望删除这些行)
请帮我纠正FILE1.TXT
的@echo off
rem %1% file name %2%range begins %3%range ends
rem Step1: this code trims the bottom section
set /a bot_trim=%3
echo Removing...
for /f "skip=%bot_trim% delims=*" %%a in (%1) do (
echo %%a >>newfile.txt
) >nul
echo Lines removed, rebuilding file...
xcopy newfile.txt %1 /y >nul
echo File rebuilt, removing temporary files
del newfile.txt /f /q >nul
echo file bottom trimmed...
rem Step2: this code trims the Top section
set /a Top_trim=%2-1
echo Removing...
for /f "skip=%Top_trim% delims=*" %%a in (%1) do (
echo %%a >>newfile.txt
) >nul
echo Lines removed, rebuilding file...
xcopy newfile.txt %1 /y >nul
echo File rebuilt, removing temporary files
del newfile.txt /f /q >nul
echo file bottom trimmed...
echo file trim completed !!
pause
内容0
aa
ff
ff
dd
dd
ee
ee
ee
为什么'trimmer.bat file1.txt 2 8'删除前10行和后15行?计数/保留空行吗? – Magoo 2014-09-19 03:46:12