如何使用批处理脚本删除文本的前三行? [英] How to remove the first and last 3 lines of a text with a batch script?

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

问题描述

Windows命令"net view/domain"按如下所示打印结果:

Windows command "net view /domain" prints result as followed:

Domain

-------------------------------------------------------------------------------
MSHOME                            
WORKGROUP            
Command Success

如何使用批处理脚本删除输出文本的前三行?

How can I remove the first and last 3 lines of the output text using a batch script?

推荐答案

@echo off
setlocal EnableDelayedExpansion
set ResultFile=Result_%random%.tmp

net view /domain > %ResultFile%
set fileLineCount=0
for /f "delims=" %%i in (%ResultFile%) do (
    set /A fileLineCount=fileLineCount+1
)

set WorkgroupFile=Workgroup_%random%.tmp
set /A LimitLine=fileLineCount-3
set Count=0
for /f "skip=3" %%i in (%ResultFile%) do (
    if !Count! LSS !LimitLine! (
        echo %%i >> %WorkgroupFile%
        set /A Count=Count+1
    ) 
)

del %ResultFile%

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

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