【发布时间】:2016-08-11 20:10:08
【问题描述】:
所以我有 2 个具有相同样式的列出内容的文件 - 字体 ID、字体定义和时间戳。我想获取新字体的第二个文件,并使用 powershell 替换第一个文件中具有匹配字体 ID 的行(没有数据库会更容易)。
File2 文本行 = [FontIDA01] 5,5,5,5,随机文本,2001 年 11 月 10 日 应替换 [FontIDA01] 匹配的 File1 行,并将 5,5,5,5 替换为 6,6,6,6,并将日期替换为该行的日期。
$content = Get-Content $fileSelected #(path chosen by user)
$masterContent = Get-Content $masterContentPath #(hardcoded path)
foreach($line in content)
{
$fontID = $line.SubString($startFontID, $endFontID)#this just sets font id = 23jkK instead of [23jkK]
foreach($masterLine in $masterContent)
{
if ($masterLine.Contains($fontID))
{
$masterContent -replace $masterLine, $line where-Object{$_.Name -contains $fontID} | Set-Content $masterContent -raw
}
}
}
我什至接近吗?
【问题讨论】:
标签: file powershell text replace edit