我正在尝试循环遍历文件并删除不需要的行。文件中的行具有唯一且不变的编号。目前我的代码在foreach循环中不能删除该行,但单独使用时可以实现。
$FSEFiles=get-childitem E:\FSE*.txt
foreach ($file in $FSEFiles)
{
try
{
(Get-Content $file.PSPath) |
Foreach-Object { Where-Object { $_ -notmatch "15987@" } } |
Foreach-Object { Where-Object { $_ -notmatch "16422@" } } |
#Foreach-Object {Where-Object { $_ -notmatch "17526@"}} |
#Foreach-Object {Where-Object { $_ -notmatch "17527@"}} |
#Foreach-Object {Where-Object { $_ -notmatch "17528@"}} |
#Foreach-Object {Where-Object { $_ -notmatch "17530@"}} |
#Foreach-Object {Where-Object { $_ -notmatch "17531@"}} |
#Foreach-Object {Where-Object { $_ -notmatch "17532@"}} |
Set-Content $file.PSPath
write-host $file updated
}
catch
{
write-host Error editing $file
}
}
我有点错过了什么,使得这个循环可以在每一行上运行?