如何使用批处理脚本删除文本的前3行和最后3行?

发布于 2024-10-09 23:14:03 字数 266 浏览 0 评论 0原文

Windows 命令“net view /domain”打印结果如下:

Domain

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜扑 2024-10-16 23:14:03
@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%
@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%
夏见 2024-10-16 23:14:03

我会使用 unix 工具 head 和/或 tail
你有 cygwin 或任何其他允许你使用 unix 命令的工具包吗
windows 有一个非常糟糕的命令列表

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文