If you're using anything Windows XP or higher, you can theoretically use Windows PowerShell. If the system is Windows Vista, then you definitely can. If it is indeed XP, then you'd need to make sure PowerShell was installed first. Here's the code:
# Windows PowerShell
# All text following a '#' is a comment line, like the 'rem' keyword in cmd
$file = Get-Content MyFile.xml # you can change this to *.xml if you wish
# split the file variable on all instances of a space
$file = $file.Split(" ")
# declare the pattern
$pattern = "findthis9=""7"""
# declare a variable to use as a counter for each occurence
for ($i = 0; $i -lt $file.GetUpperBound(""); $i++)
{
if ($file[$i] -match $pattern)
{
++$counterVariable
}
}
return $counterVariable
Also, if you turned this into a function, then you could do it by file, because you could return the filename with the number of times it appears in the file. See below:
function Count-NumberOfStringInstances()
{
[CmdletBinding()]
# define the parameters
param (
# system.string[] means array, and will allow you to enter a list of strings
[Parameter()]
[System.String[]]$FilePath,
[Parameter()]
[System.String]$TextPattern
)
$counterVariable = 0
$files = Get-ChildItem -Path $FilePath
$file = Get-Content $FilePath # you can change this to *.xml if you wish
# split the file variable on all instances of a space
$file = $file.Split(" ")
# declare the pattern
# declare a variable to use as a counter for each occurence
for ($i = 0; $i -lt $file.GetUpperBound(""); $i++)
{
if ($file[$i] -match $TextPattern)
{
++$counterVariable
}
}
# return the counter variable
return $counterVariable
}