本帖最后由 tmplinshi 于 2022-12-20 07:39 编辑
试试 PowerShell- function ParseFile {
- param (
- [Parameter(Mandatory = $true)][Alias("in")] $inputFile,
- [Parameter(Mandatory = $true)][Alias("out")] $outputFile
- )
-
- if (-not (Test-Path $inputFile)) {
- Write-Error "文件不存在: $inputFile"
- return
- }
-
- $streamIn = [IO.StreamReader]::new($inputFile)
- $streamOut = [IO.StreamWriter]::new($outputFile, $false, [System.Text.ASCIIEncoding]::UTF8)
-
- while (-not $streamIn.EndOfStream) {
- $line = $streamIn.ReadLine()
- $arr = $line -split '-+'
- if ($arr[1, 2] -join '-' -like "*$($arr[0])*") {
- $streamOut.WriteLine($line)
- }
- }
-
- $streamIn.close()
- $streamOut.close()
- }
-
- ParseFile -in a.txt -out b.txt
复制代码
|