我想在.txt文档中的每行文本末尾添加字符。使用PowerShell将文本添加到文本文件中的每一行
#Define Variables
$a = c:\foobar.txt
$b = get-content $a
#Define Functions
function append-text
{
foreach-Object
{
add "*"
}
}
#Process Code
$b | append-text
就是这样的。实质上,加载一个给定的文本文件,在该文本文件中的每一行文本的末尾添加“*”,保存并关闭。
如果您使用过滤器,则根本不需要`process`块。 `过滤追加文本{“$ _ *”}` – 2011-02-10 03:49:34
这很好用!有没有可能在此添加冗余检查?一些会检查“*”的存在,如果它不在行尾,然后添加它? – Joshua 2011-02-10 04:10:34
当然,`过滤追加文本{if($ _ -match'\ * \ s * $'){$ _} else {“$ _ *”}}` – 2011-02-10 04:30:55