从显示文本文件行批处理文件

编程入门 行业动态 更新时间:2024-10-28 17:24:42
本文介绍了从显示文本文件行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

喜我试着找到一个脚本,可以让我显示行号#行号和#以及#线 - #从一个批处理文件的文本文件?我在这里找到这个脚本在这个网站。

Hi I'm tryin' to find a script that will let me display "linenumber# and linenumber# as well as lines#-#" from a text file in a batch file? I found this script here on this site..

@echo off setlocal enabledelayedexpansion if [%1] == [] goto usage if [%2] == [] goto usage SET /a counter=0 for /f "usebackq delims=" %%a in (%2) do ( if "!counter!"=="%1" goto exit echo %%a set /a counter+=1 ) goto exit :usage echo Usage: head.bat COUNT FILENAME :exit

和它的伟大工程:)但它抓住的行数从文本文件的顶部。我想能够显示在文本文件中的某些线,以及一个范围,如果可能..

And it works great :) But it grabs the number of lines from the top of the text file. I want to be able to display certain lines in the text file, as well as a range if possible..

EG:我有30行的文本文件,我想显示1-4行; 7-11; 13; 17-20; 22; 26安培; 29

EG: I have a text file with 30 lines, and I want to display lines 1-4; 7-11; 13; 17-20; 22; 26 & 29

推荐答案

下面是上面的示例批处理文件的一个简单的修改。复制code以下为文件并将其命名为LineDisplay.bat - 它采用FirstLineNumber和LastLineNumber作为参数。例如:LineDisplay test.txt的12月30日(读线12-30)

Here's a simple modification of the sample batch file above. Copy the code below to file and name it "LineDisplay.bat" - it takes the FirstLineNumber and LastLineNumber as parameters. Example: LineDisplay test.txt 12 30 (to read lines 12-30)

@echo off setlocal enabledelayedexpansion if [%1] == [] goto usage if [%2] == [] goto usage if [%3] == [] goto usage set /a FirstLineNumber = %2 set /a LastLineNumber = %3 echo Reading from Line !FirstLineNumber! to !LastLineNumber! SET /a counter=1 for /f "usebackq delims=" %%a in (%1) do ( if !counter! GTR !LastLineNumber! goto exit if !counter! GEQ !FirstLineNumber! echo !counter! %%a set /a counter+=1 ) goto exit :usage echo Usage: LineDisplay.bat FILENAME FirstLineNumber LastLineNumber :exit

下面是一条线,一个很好的教程创建批处理文件 HTTP: //vtatila.kapsi.fi/batch_tutorial.html

Here's a line to a nice tutorial on creating batch files vtatila.kapsi.fi/batch_tutorial.html

更多推荐

从显示文本文件行批处理文件

本文发布于:2023-05-27 19:34:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/300604.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   批处理文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!