# --- $groups is 6 separate .TXT files
$groups=@(Grp-1,Grp-2,Grp-3,Grp-4,Grp-5,Grp-6)
# --- $titles is a .CSV file, each line containing a few words (book title)
$titles = Import-csv .\Mysource.csv
# --- check existence of each line in $titles in each of the 6 groups in $groups
$dups = Foreach ($mt in $titles) {
[string]$mtstring = $mt.TitleWoYear
Foreach ($g in $groups) {
$Gfile = 'C:\TEMP\ + $g + '.txt'
$thisgroup = Get-content -path $Gfile
$thisgroup | Out-string -stream |
Select-string -pattern $mtstring -simplematch -list
}
}
$dups | Out-gridview
The above works OK. I have grappled with how I can include the value of $g (a file name) into the output using Out-Gridview (if possible?) I tried reversing the inner Foreach loop with the outer Foreach loop but discovered the -Begin / -Process / -End blocks are not allowed in Foreach ($a in $b) looping, only for Foreach-object (pipelining). Would be grateful for some advice or insights/tips. Many thanks.