fireburn11
asked on
scirpt to compare Text file A with Text file B
Hi Guys,
I need a script that can compare text file A with text file B. If any line in text file A is found in text file B, print that line out onto the screen or into a text file.
it can be vb, powershell, batch.
Please advise.
Thanks
I need a script that can compare text file A with text file B. If any line in text file A is found in text file B, print that line out onto the screen or into a text file.
it can be vb, powershell, batch.
Please advise.
Thanks
Well after looking at what you're doing, I think you're making a list in one file and the output is in the other.
In this case, you could do a simple foreach loop in Powershell to do it.
$matches = get-content "C:\Scripts\FileA.txt"
$output = get-content "C:\Scripts\FileB.txt"
foreach ($match in $matches){
foreach ($line in $output){
if ($match -eq $line){Write-Host $line}
}
}
In this case, you could do a simple foreach loop in Powershell to do it.
$matches = get-content "C:\Scripts\FileA.txt"
$output = get-content "C:\Scripts\FileB.txt"
foreach ($match in $matches){
foreach ($line in $output){
if ($match -eq $line){Write-Host $line}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, very nice improvement bchallis. Thanks for testing that. I knew it wasn't the most efficient either with two foreach loops nested.
Here's how to do it with a simple BAT or command line command:
findstr /i /g:a.txt b.txt
~bp
ASKER
Great solution!
http://technet.microsoft.com/en-us/library/ee156812.aspx
Compare-Object $(Get-Content c:\scripts\x.txt) $(Get-Content c:\scripts\y.txt)
DH