I am the best. Page I am good. Page I am funny. Page
Output:
4 I am the best. Page 4 I am good. Page 4 I am funny. Page
PowerShell script needs to look for “page” and add “4” at the beginning of the line. I have created this script:
powershell -Command “sed ‘s/^Page/4 &/‘c:\users*.txt >test.txt”
但它在 PowerShell 中不起作用。
最佳答案
这应该可以做到:
$content = Get-Content "C:\path\to\my\file.txt"
$newcontent = $null
Foreach($line in $content)
{
if($line -ne "")
{
$line = "4 "+"$line`r`n"
$newcontent += $line
}
else
{
$newcontent += "`r`n"
}
}
Set-Content -Path "C:\path\to\my\file.txt" -Value $newcontent
关于linux - PowerShell 脚本查找文件中的特定单词并在行开头添加 “4”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47800405/