test.ps1- $srcFile = '1.txt'; #源文件名
- $dstFile = '2.txt'; #修改后的文件名
- $hash = @{};
- $res = [Collections.ArrayList]@();
-
- forEach( $strLine In [IO.File]::ReadAllLines($srcFile, [Text.Encoding]::Default) ){
- $arr = $strLine.Trim().Split();
- if( $arr.Count -eq 2 -and !$hash.ContainsKey($arr[1]) ){
- $hash.Add( $arr[1], $true );
- [void]$res.Add( $strLine );
- }
- }
-
- [IO.File]::WriteAllLines( $dstFile, $res, [Text.Encoding]::Default );
复制代码
|