使用批处理脚本读取每5日线 [英] Read every 5th line using Batch Script
本文介绍了使用批处理脚本读取每5日线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想和将显示一个文本文件的每一五号线,线一样没有1,6,11,16批处理程序....
我试图修改head.bat code在这里找到: Windows批处理命令(S)来读取文本文件第一行
I want to make a batch program with will display every 5th line of a text file, like line no 1, 6, 11, 16 .... I tried modifying head.bat code found here: Windows batch command(s) to read first line from text file
我的code是象下面这样:
My code is like below:
@echo off
setlocal enabledelayedexpansion
if [%1] == [] goto usage
SET /a counter=0
for /f "usebackq delims=" %%a in (%1) do (
set /a testcond=(%%counter-1)%4
if "!testcond!"=="0" echo %%a
set /a counter+=1
)
goto exit
:usage
echo Usage: fifth FILENAME
:exit
这code不工作。能否请你告诉我什么是错这个code?
This code is not working. Can you please tell me what is the wrong with this code?
推荐答案
好像你需要改变一行在脚本如下:
Seems like you need to change one line in your script as follows:
@echo off
setlocal enabledelayedexpansion
if [%1] == [] goto usage
SET /a counter=0
for /f "usebackq delims=" %%a in (%1) do (
set /a "testcond=(counter-1)%%5"
if "!testcond!"=="0" echo %%a
set /a counter+=1
)
goto exit
:usage
echo Usage: fifth FILENAME
:exit
现在脚本应该工作。
这篇关于使用批处理脚本读取每5日线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文