Untitled

 avatar
unknown
plain_text
a year ago
791 B
3
Indexable
# Initialize a dictionary to store match counts
$matchCount = @{}

# Open the file and read it line by line
$file = "your_file_path.txt"
Get-Content -Path $file | ForEach-Object {
    # Find matches using regex in the current line
    $matches = [regex]::Matches($_, '>([0-9]+)<')
    
    # Count the occurrences of each matched number in the current line
    foreach ($match in $matches) {
        $number = $match.Groups[1].Value
        if ($matchCount.ContainsKey($number)) {
            $matchCount[$number]++
        } else {
            $matchCount[$number] = 1
        }
    }
}

# Display the results
foreach ($entry in $matchCount.GetEnumerator() | Sort-Object -Property Value -Descending) {
    Write-Output "$($entry.Key): $($entry.Value) occurrences"
}
Editor is loading...
Leave a Comment