in a txt file I have this line:
<em:version>0.0.0.2</em:version>
Which cmd (dos or powershell) can I use fetch this?
0.0.0.2
PS> '<em:version>0.0.0.2</em:version>' -replace '<[^>]+>'
0.0.0.2
# replace file content
(Get-Content file.txt) -replace '<[^>]+>'
PowerShell can parse XML directly. No need for regular expressions. Here's an example with a FireFox install.rdf file. (I'm guessing your file might be something like that.)
PS> [xml]$rdf = Get-Content .\install.rdf
PS> $rdf.RDF.Description.version
1.0
try this
$fileContent=gc "path to text file"
$pattern = '(?i)<em:version[^>]*>(.*)</em:version>'
$result = [Regex]::Matches($fileContent, $pattern)
$result | ForEach-Object {
$_.Groups[1].Value
}
How about this? A one line DOS command:
for /f "usebackq tokens=2 delims=<>" %%A in (`type "File.txt" ^| find "<em:version>"`) do echo.%%A