我有一些文本文件,看起来像这样:
文本 05-09-18
文本 17-09-18
文本 17-09-18
文本 24-09-18
文本 17-10-18
在 .txt 文件的第 15 行,我尝试将 24-09-18 更改为 24-09-2018。
只改变这个,不改变其他。
这是我到目前为止一直在做的事情:
$infolder = Get-ChildItem C:\folder\*.txt -rec
foreach ($file in $infolder)
{
(Get-Content $file.PSPath) |
Foreach-Object { $_[15] -replace '-18','-2018'} |
Set-Content $file}
Run Code Online (Sandbox Code Playgroud)