Hi @Suzana Eree ,
You can implement the loop like this
$file1 = 'D:\temp\file1.html'
$file2 = 'D:\temp\file2.html'
$result = 'D:\temp\result.html'
$link=@()
$title=@()
$number=@()
Get-Content -Path $file1 -Delimiter '</li>'|ForEach-Object{
$_|ForEach-Object{
if($_ -match '(?<=href=").+?(?=")'){$link += $Matches.Values}
if($_ -match '(?<=title=").+?(?=")'){$title += $Matches.Values}
if($_ -match '(?<=\()\d+(?=\))'){$number += $Matches.Values}
}
}
$content = Get-Content -Path $file2 -Delimiter '</div>'
for($i=0;$i -lt $content.Count;$i++){
$content[$i] | ForEach-Object{
if($_ -match '(?<=href=").+?(?=")'){$link2 = $Matches.Values}
if($_ -match '(?<=title=").+?(?=")'){$title2 = $Matches.Values}
if($_ -match '(?<=<span>)\d+(?=</span>)'){$number2 = $Matches.Values}
}
$content[$i] -replace $link2, $link[$i] -replace $title2, $title[$i] -replace $number2, $number[$i] | Out-File -FilePath $result -Append
}
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.