开发者

How to remove the first and last 3 lines of a text with a batch script?

开发者 https://www.devze.com 2023-02-02 02:50 出处:网络
Windows command \"net view /domain\" prints result as followed: Domain -------------------------------------------------------------------------------

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

Domain

-------------------------------------------------------------------------------
MSHOME                            
WOR开发者_运维百科KGROUP            
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%


i would use the unix tools head and/or tail do you have cygwin or any other toolkit that allows you to use unix commands windows has a vey poor command list

0

精彩评论

暂无评论...
验证码 换一张
取 消