First I would like to generate a directory listing for all text files in a directory. Next take each of those text files and get-contents. Then I want to go through the contents and search for all text files in another directory which share contents with the first file and output those corresponding matches to a file named after the source file.
I’m very new at all of this and realize I’m missing some serious fundamental chunks of knowledge. What little scripting experience I have is in Javascript which doesn’t seem entirely transferable. (Although programming is programming I’m told.)
This is what I have so far:
$max = get-content h:test1\one.txt | Measure-Object
$A = get-content h:test1\one.txt
For($i=0; $i -lt $max.count ; $i++){
select-string h:test2\*.txt -pattern $($A[$i]) | Format-Table | Out-File ($i + '.txt')
}
I’m hoping for something like:
$max = get-content $files[i] | Measure-Object
$A = get-content files[i]
For($j=0; $j -lt $max.count ; $j++){
select-string h:test2\*.txt -pattern $($A[$j]) | Format-Table | Out-File($files[i].basename + $j + '.txt')
}
Any and all help would be extremely appreciated,
Kurtis
So
Book 1 (one.txt)
The capital of France is Paris.
The population of Paris is twelve.
Book 2 (two.txt)
France is a beautiful country.
The capital of France is Paris.
I basically want a report of the fact that two.txt shares a line with one.txt.
OK let’s break this down:
OK, now we pipe all that text to
select-string(first filtering out all empty string with?{$_}:So now it gets tricky because we have to go back and track our source file name, we do this by wraqpping our query in a foreach (i.e.
%{}):