CMD.EXE 批处理脚本显示 txt 文件的最后 10 行 [英] CMD.EXE batch script to display last 10 lines from a txt file

查看:81
本文介绍了CMD.EXE 批处理脚本显示 txt 文件的最后 10 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法如何回显或输入 txt 文件的最后 10 行?

Any ideas how to echo or type the last 10 lines of a txt file?

我正在运行一个服务器更改日志脚本来提示管理员说明他们在做什么,以便我们可以跟踪更改.我试图让脚本显示最近 10 个左右的条目,以了解最近发生的事情.我找到了一个处理最后一行的脚本,如下所示,但无法弄清楚在其中更改什么以显示最后 10 行.脚本:

I'm running a server change log script to prompt admins to state what they're doing, so we can track changes. I'm trying to get the script to show the last 10 entries or so to give an idea of what's been happening recently. I've found a script that deals with the last line, as shown below, but can't figure out what to change in it to display the last 10 lines. Script:

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (c:log09.txt) do (
set var=%%a
)
echo !var!

日志文件示例:

06/02/2009, 12:22,Remote=Workstation-9,Local=,
mdb,bouncing box after updates,CAS-08754,
=================
07/02/2009, 2:38,Remote=,Local=SERVER1,
mdb,just finished ghosting c drive,CAS-08776,
=================
07/02/2009, 3:09,Remote=,Local=SERVER1,
mdb,audit of server,CAS-08776,

有什么想法吗?该脚本运行良好,只需要将更多行通过管道传输到屏幕即可.

Any thoughts? The script works great, just need it to pipe more lines to the screen.

推荐答案

希望这能拯救乔尔的眼睛 :)

Hopefully this will save Joel's eyes :)

@echo OFF

:: Get the number of lines in the file
set LINES=0
for /f "delims==" %%I in (data.txt) do (
    set /a LINES=LINES+1
)

:: Print the last 10 lines (suggestion to use more courtsey of dmityugov)
set /a LINES=LINES-10
more +%LINES% < data.txt

这篇关于CMD.EXE 批处理脚本显示 txt 文件的最后 10 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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