windows – Fetching the matched string from the text using findstr – Education Career Blog

I have a text in some file like

<Variable name="URL"  value="http://url:port"/>

I want the url in the value tag( http://url:port ).

The command and regex I’m using are

FindStr /R /C:"\"URL\" *value=*\"*\"" <filename>

The above regex matches the line in the file but fails to extract that url string

any suggestion?


findstr will not capture any values for you. If you can download tools, you can try gawk for windows

C:\test>gawk "/value/{ gsub(/.*value=\042|\042.*/,\"\");print }" file

If not, you can use vbscript

strFile= WScript.Arguments(0)
Set objFS = CreateObject( "Scripting.FileSystemObject" )
Set d = CreateObject("Scripting.Dictionary")
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
    If InStr(strLine,"value=") > 0 Then
        WScript.Echo s1
    End If


C:\test>cscript //nologo test.vbs file

Leave a Comment