本帖最后由 yhcfsr 于 2019-3-9 18:30 编辑
楼上代码高大上,我来一个笨拙的- @Powershell "& {[ScriptBlock]::Create("'#' + (gc '%~f0' -raw)").Invoke()}" & pause & goto :eof
- $text_A = type a.txt -ReadCount 0;
- $text_B = type b.txt -ReadCount 0;
-
- $count_a, $count_b = $text_A.Count, $text_B.Count;
- $count = $count_a + $count_b;
-
- [System.Collections.ArrayList] $result = @();
-
- $counter_a, $counter_b = 0, 0;
- for($i=0;$i -lt $count;$i++)
- {
- #如果A文本读完,只处理B
- if($counter_a -eq $count_a) { [void] $result.Add($text_B[$counter_B++]); }
-
- #如果B文本读完,只处理A
- elseif($counter_b -eq $count_b) { [void] $result.Add($text_A[$counter_a++]); }
-
- #如果A,B都未完,下标为偶数时,加入A元素;下标为奇数时,加入B元素
- else {
- if($i%2 -eq 0) {[void] $result.Add($text_A[$counter_a++]); }
- else {[void] $result.Add($text_B[$counter_b++]); }
- }
- }
-
- #输出结果
- [io.file]::WriteAllLines('结果.txt',$result,[text.encoding]::Default);
复制代码
|