如果我在文本文件中有5个单词
red car
yellow flower
purple heart
vault of grass
hard light
如何搜索单词然后将其删除并保存/覆盖...在python中很容易,但对于我而言,powershell对我来说有点复杂。
#name new file
$fileName = read-host "Enter fileName: "
#create new text file to save processes
$textFile = New-Item C:\Users\socrateslouis\Documents\$folderName\$fileName".txt" -type file
#store in text file
$outfile =Get-Process | Out-File -FilePath C:\Users\socrates\Documents\$folderName\$fileName".txt"
#display processes
$processFile = Get-Content C:\Users\socrates\Documents\$folderName\$fileName".txt"
$processFile
答案 0 :(得分:1)
$File = 'TestFile.txt'
$tempFile = 'TestFileTmp.txt'
$stringToMatch = "vault"
Get-Content $File | Where { $_ -notmatch $stringToMatch } | Set-Content $tempFile
Remove-Item -Path $File
Rename-Item -Path $tempFile -NewName $File -Force