[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. @if(0)==(0) echo off
  2. type 1.txt | cscript //nologo //e:jscript "%~f0" > 2.txt
  3. pause & exit /b
  4. @end
  5. var obj = {};
  6. while( !WSH.StdIn.AtEndOfStream ){
  7.     var s = WSH.StdIn.ReadLine();
  8.     var m = s.match(/^\S+\t(\S+)$/);
  9.     if( m == null || obj.hasOwnProperty(m[1]) ) continue;
  10.     obj[m[1]] = true;
  11.     WSH.Echo(s);
  12. }
复制代码

TOP

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

TOP

返回列表