脑子不好又不是换个编码就能解决的,gawk不会弄,弄不出来,但是用powershell弄出来了
input.txt是输入文件
output.txt是输出文件
ansi是编码,可以换成utf8,utf16le,utf16be | | | | | $inf="input.txt" | | $otf="output.txt" | | $cod="ansi" | | | | $sList=@{ | | "公司"=1; | | "企业"=2; | | "名称"=3; | | "货号"=4; | | "编号"=5; | | "品类"=6 | | } | | $s="公司|企业|名称|货号|编号|品类" | | | | $inf=$pwd.path+"\"+$inf | | $otf=$pwd.path+"\"+$otf | | $thecod=@{ | | "ansi"=[text.encoding]::Default; | | "utf8"=[text.encoding]::UTF8; | | "utf16le"=[text.encoding]::Unicode; | | "utf16be"=[text.encoding]::BigEndianUnicode | | } | | $a=[io.file]::ReadAllLines($inf,$thecod[$cod]) | | $b=[System.Collections.ArrayList]::new() | | $c=[System.Collections.ArrayList]::new() | | | | (0..($a.Length-1)).ForEach({ | | if($a[$_] -and ($a[$_] -match $s)){[void]$b.add(@($_,$a[$_]))} | | elseif($a[$_]){[void]$c.add(@($_,$a[$_]))} | | }) | | | | if(!$b -and !$c){exit} | | | | $aa=[io.file]::OpenWrite($otf) | | $aaa=[System.IO.StreamWriter]::new($aa,$thecod[$cod]) | | | | if($b){$d=[object[]]($b|group {$_[1].split(' ')[0,3] -join ''})} | | | | $e=[object[]]($d|?{$_.count -gt 1}) | | if($e){ | | (0..($e.Count-1)).ForEach({ | | $e[$_].Group|sort {$tmp=[regex]::Match($_[1],$s).value;$sList[$tmp]},{$_[0]}|%{$aaa.writeline($_[1])} | | $aaa.WriteLine() | | }) | | } | | | | $e=[object[]]($d|?{$_.count -eq 1}) | | if($e){(0..($e.Count-1)).ForEach({[void]$c.add(@($e[0].group[$_][0],$e[0].group[$_][1]))})} | | if($c){$c|sort {$_[0]}|%{$aaa.WriteLine($_[1])}} | | | | $aaa.close()COPY |
|