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
http://url:port
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
strLine=objFile.ReadLine
If InStr(strLine,"value=") > 0 Then
s=Split(strLine,"value=")
s1=Replace(s(1),"/>","")
WScript.Echo s1
End If
Loop
usage:
C:\test>cscript //nologo test.vbs file
"http://url:port"