本帖最后由 yhcfsr 于 2019-1-25 23:22 编辑
回复 3# meiszp
问题是第5次之前,你还有要删除的行,那以什么标准去判断是否要删除行?
最好把测试文件上传到网上.
将一个或多个要处理的文件拖入bat即可- <# :将文件拖入bat执行
- @echo off&cd/d "%~dp0"
- set "batfile=%~0"&set "psfile=%~dpn0.ps1"
- :lp
- set "args=%args%"%~1" "
- shift
- if "%~1" neq "" goto :lp
- more +13 "%batfile%">"%psfile%"
- powershell -Nologo -NoProfile -Exec bypass -file "%psfile%" %args%
- del /f /q "%psfile%"
- pause&exit
- #>
-
-
- foreach($arg in $args)
- {
- $file=$arg;
- $count=0;
- [system.collections.arraylist] $result=@();
- $content=type $file -ReadCount 0;
- foreach($line in $content)
- {
- if(($line -match '^\d+\s*$') -or ($line -match '^\s+- \d+ -\s*$')){continue;}
- if($line -match 'KRITISCHE DREHZAHL'){$count+=1}
- [void] $result.Add($line)
- if($count -ge 5){break;}
- }
- [io.file]::WriteAllLines($($file+'.log'),$result,[text.encoding]::default);
- }
复制代码
|