批处理文件删除前3行文本文件 [英] Batch file to delete first 3 lines of a text file

查看:906
本文介绍了批处理文件删除前3行文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题状态,我需要一个批处理文件删除前3行中的文本文件。

As the title states I need a batch file to delete the FIRST 3 lines of a text file.

例如:

A    
B    
C    
D    
E   
F    
G

在这个例子中,我需要A,B和C线沿线删除

in this example I need A,B and C deleted along with the line

推荐答案

这应该这样做。

for /f "skip=3 delims=*" %%a in (C:\file.txt) do (
echo %%a >>C:\newfile.txt    
)
xcopy C:\newfile.txt C:\file.txt /y
del C:\newfile.txt /f /q

这将重新创建与前3行中删除的文件。

That will re-create the file with the first 3 lines removed.

要保持更新,你可以在命令提示符下在VBScript样式或输出消息批处理文件整合消息的用户。

To keep the user updated you could integrate messages in the batch file in vbscript style or output messages in the command prompt.

@echo off
echo Removing...
for /f "skip=3 delims=*" %%a in (C:\file.txt) do (
echo %%a >>C:\newfile.txt
) >nul
echo Lines removed, rebuilding file...
xcopy C:\newfile.txt C:\file.txt /y >nul
echo File rebuilt, removing temporary files
del C:\newfile.txt /f /q >nul
msg * Done!
exit >nul

希望这有助于。

这篇关于批处理文件删除前3行文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆