【发布时间】:2011-11-19 16:31:21
【问题描述】:
好的,所以我已经建立了一个哈希表,其中名称是要替换的内容,键是要替换的内容,如下所示:
$r = @{
"dog" = "canine";
"cat" = "feline";
"eric" = "eric cartman"
}
接下来我该怎么做?我试过这个:
(Get-Content C:\scripts\test.txt) | Foreach-Object {
foreach ( $e in $r.GetEnumerator() ) {
$_ -replace $e.Name, $e.Value
}
} | Set-Content C:\scripts\test.txt.out
但它根本不起作用,它只是每行写三遍,没有替换任何东西。
编辑:包含 test.txt:
dog
cat
eric
test.txt.out:
dog
dog
dog
cat
cat
cat
eric
eric
eric
【问题讨论】:
-
C:\scripts\test.txt 的内容是什么??
标签: powershell replace hashtable