[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
ps1
  1. $content = Get-Content -Path "1.txt" -Raw
  2. $count = @{}
  3. $content -split '\r?\n' | ForEach-Object {
  4.     $line = $_
  5.     Select-String -InputObject $line -Pattern "\b[a-zA-Z]+\b" -AllMatches | ForEach-Object {
  6.         $match = $_.Matches[0]
  7.         $word = $match.Value
  8.         if ($count.ContainsKey($word)) {
  9.             $count[$word]++
  10.         } else {
  11.             $count[$word] = 1
  12.         }
  13.         $line = $line.Replace($word, "$word" + $count[$word].ToString())
  14.     }
  15.     $line
  16. } | Out-File -FilePath "2.txt"
复制代码

TOP

返回列表