views:

40

answers:

2

In my bat script, is it possible to access a txt file and read it line by line. The idea I'm having 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.

+1  A: 

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
)
Ruel
+2  A: 

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
ghostdog74