批处理如何实现删除多个txt文本的最后两行内容

admin 2017年11月9日10:07:34系统文档评论2,338 次浏览阅读模式

BAT:

  1. @echo off&setlocal enabledelayedexpansion

  2. for %%i in (*.txt) do (

  3. set "f=%%i"

  4. for /f "usebackq delims=" %%j in ("!f!") do set/a n+=1

  5. set/a n-=1

  6. for /f "delims=" %%m in ('"type "!f!"|more& cd. 2^>!f!"') do set/a x+=1&if !x! leq !n! echo;%%m>>!f!

  7. set/a n=0,x=0

  8. )

  9. pause

PYTHON3

  1. import os

  2. import sys

  3.   

  4. try:

  5.     file_name = sys.argv[1]

  6. except Exception as e:

  7.     print('请拖放待处理文件到本脚本')

  8. with open(file_name, 'r') as f:

  9.     lines = f.readlines()

  10. with open(file_name, 'w') as f:

  11.     f.write(''.join(lines[2:]))

相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2017年11月9日10:07:34
  • 转载请务必保留本文链接:https://anyun.org/a/jishuguanzhu/xitongwendang/2017/1109/9265.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: