I have 2 sets of operations, in the 1st one I look for files that contain a string, then in second one I use that list to extract lines that contains another string and then edit them.
$List_Of_Files = Get-ChildItem "$outputfolder*.html" -recurse |
Select-String -pattern "https://www.youtube.com" | group path |
select name -ExpandProperty Name
$List_Of_Titles = @(Get-Content $List_Of_Files | Where-Object { $_.Contains("<title>") }) |
Foreach-Object {
$content = $_ -replace " <title>", " <video:title>";
$content -replace "</title>", "</video:title>"
}
Code works as expected, but the problem is that I need the 1st set of operations to output results into a text file and then use that file in second set which should also output results into another text file.
I have tried the following, but second set doesn't create the file, but doesn't give me any error either.
Get-ChildItem "$outputfolder*.html" -recurse |
Select-String -pattern "https://www.youtube.com" | group path |
select name -ExpandProperty Name | Set-Content "c:\List_Of_Files.txt"
@(Get-Content "c:\List_Of_Files.txt" | Where-Object { $_.Contains("<title>") }) |
Foreach-Object {
$content = $_ -replace " <title>", " <video:title>";
$content -replace "</title>", "</video:title>"
} | Set-Content "c:\list_of_titles.txt"
I have tried to modify it in different ways, but can't figure out how to make it work.
Set-Contentproduces ASCII files by default, causing any foreign chars. to be replaced with literal?chars.; if that's a problem, use the-Encodingparameter to change that.