开发者

bat read a file line by line

开发者 https://www.devze.com 2023-01-18 03:16 出处:网络
In my bat script, is it possible to access a txt file and read it line by line. The idea I\'m havi开发者_C百科ng is to check if the line starts with an identifier word (in my case 1 or 2 stars * or **

In my bat script, is it possible to access a txt file and read it line by line. The idea I'm havi开发者_C百科ng is to check if the line starts with an identifier word (in my case 1 or 2 stars * or **) but to do this I need to read the file line by line.


you can use vbscript

strToFind= WScript.Arguments(0)
strToFind = Replace(strToFind,"*","\*")
strFileName = WScript.Arguments(1)
Set objFS = CreateObject( "Scripting.FileSystemObject" )
Set objFile = objFS.OpenTextFile(strFileName)
Set objRE = New RegExp
objRE.IgnoreCase = False
objRE.Pattern = "^"&strToFind&".*"
Do Until objFile.AtEndOfStream    
    strLine = objFile.ReadLine
    Set Matches = objRE.Execute(strLine)
    'WScript.Echo Matches.Count
    For Each Match in Matches   ' Iterate Matches collection.             
        WScript.Echo Match.Value        
    Next        
Loop       
objFile.Close

Usage:

C:\test>cscript //nologo myscript.vbs "**" file


Here's what I found: http://www.computing.net/howtos/show/batch-file-tip-reading-writing-every-line-of-a-file/61.html

Hope that helps..

CODE:

@echo off
for /f "delims=] tokens=1*" %%a in ('find /v /n "" ^<%1') do (
   echo.%%b
)
0

精彩评论

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