3
我想通過文件循環並刪除不需要的行。文件中的行具有不會更改的唯一編號。到目前爲止,我沒有在foreach循環中刪除該行,但分開執行。通過文件循環並刪除幾行不同的文本
$FSEFiles=get-childitem E:\FSE*.txt
foreach ($file in $FSEFiles)
{
try
{
(Get-Content $file.PSPath) |
Foreach-Object { Where-Object { $_ -notmatch "[email protected]" } } |
Foreach-Object { Where-Object { $_ -notmatch "[email protected]" } } |
#Foreach-Object {Where-Object { $_ -notmatch "[email protected]"}} |
#Foreach-Object {Where-Object { $_ -notmatch "[email protected]"}} |
#Foreach-Object {Where-Object { $_ -notmatch "[email protected]"}} |
#Foreach-Object {Where-Object { $_ -notmatch "[email protected]"}} |
#Foreach-Object {Where-Object { $_ -notmatch "[email protected]"}} |
#Foreach-Object {Where-Object { $_ -notmatch "[email protected]"}} |
Set-Content $file.PSPath
write-host $file updated
}
catch
{
write-host Error editing $file
}
}
我錯過了什麼可以讓這個循環在每一行工作嗎?
完美!這正是我所需要的。 謝謝。 – Alan
很高興幫助。請考慮在左邊的選票下標上這個答案。 – Matt