- <# :
- cls&echo off&cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $file1="A.txt";
- $file2="B.txt";
-
- if(-not (test-path -literal $file1)){write-host ('"'+$file1+'" not found');exit;}
- if(-not (test-path -literal $file2)){write-host ('"'+$file2+'" not found');exit;}
-
- $enc=[Text.Encoding]::GetEncoding('GB2312');
- $dic=New-Object 'System.Collections.Generic.Dictionary[string, string]';
- $text2=[IO.File]::ReadAllLines($file2, $enc);
- for($i=0;$i -lt $text2.length;$i++){
- $m=[regex]::match($text2[$i], '(\d+) *//([^\r\n]+)');
- if($m.Success){
- $k=$m.groups[2].value.ToLower();
- if(-not $dic.ContainsKey($k)){$dic.add($k, $m.groups[1].value);}
- }
- }
-
- $text1=[IO.File]::ReadAllText($file1, $enc);
- $text1=[regex]::replace($text1, '(TitleList.Url.\d+=([^\r\n]+)[\s\S+]*?TitleList.ContextNumber.\d+=)[^\r\n]*', {
- param($m);
- $k=$m.groups[2].value.ToLower();
- if($dic.ContainsKey($k)){
- $m.groups[1].value+$dic[$k];
- }else{$m.groups[0].value;}
- });
- [IO.File]::WriteAllText($file1, $text1, $enc);
复制代码
|