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

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

问题描述

任何想法如何回声或键入的最后10行一个txt文件的?

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天全站免登陆