标签:os 文件 io for cti ar line new
#定义要查找的包含某个关键字的行(该关键字不是要替换的内容,比如此处要替换的是行 Hostname=10.4.20.20 中等号后面的内容)
$keyword = "Hostname"
#定义要替换后的内容
$newword = "10.4.20.20"
$filepath = "C:\zabbix_agent\conf\zabbix_agentd.win.conf"
Function SearchReplace ($keyword,$newword,$filepath)
{
$confs = gc $filepath
$linekeyword = (Select-String -Path $filepath -Pattern $keyword -List).Line
#定义要被替换的内容
$replaceword = $linekeyword.Split("=")[1]
Clear-Content $filepath
foreach ($line in $confs)
{
$lineold = $line.Split("=")[1]
$linenew = $line.Replace($replaceword,$newword)
Add-Content $filepath -Value $linenew
}
}
标签:os 文件 io for cti ar line new
原文地址:http://www.cnblogs.com/dreamer-fish/p/3880339.html