Jer*_*emy 1 arrays powershell scripting
我有一个完整的行文件,我想删除任何与数组中的字符串匹配的行,使用PowerShell:
$stringsiDoNotWant = @("admin", "student")
$content = gc file.txt
Run Code Online (Sandbox Code Playgroud)
但
$content = $content -notcontains $StringsiDoNotWant
Run Code Online (Sandbox Code Playgroud)
不起作用:我在变量中仍然有"admin"和"student" $content.
试试这个:
(Get-Content file.txt) | Where {$_ -notmatch 'admin|student'} | Out-File somefile.txt
Run Code Online (Sandbox Code Playgroud)
要么
$content = Get-Content file.txt
$content = $content | Where {$_ -notmatch 'admin|student'}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |