我想修剪頂部和底部的文本文件。 說出文本文件是否包含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