I'm looking for something to do some batch file comparison. I had a master config file which I want to compare to somewhere up to around 400 files where it will contain all of the master file plus in some cases, a couple (mostly likely to be a single line or two) differences - I want to capture these so I can add into my master file. I don't mind doing the merge part manually as I means I can get shut of anything I no longer need to create a new 'master' Any suggestions for software which could make this process easy? I've found lots of title which do 2 or 3 file compare but I'd like to point to a file and say compare each one in this folder. I could likely do something in powershell to solve this one problem but if there is some software already out there, it might be good to keep in my tool belt for the future
Bash, through wsl or any linux system. Or mac. for file in $(ls /path/to/folder/*); do diff /path/to/original.txt $file; done
Just plain text files I’ll give that Linux way a try, I figure there might be some Linux minds coming to help on this one, sadly my skill set in that area is pretty limited.
i'm no expert and this might be too jank to be useful but it also might point you in the right direction - powershell - Code: $prime = Get-Content C:\\path\\to\\masterfile.txt Get-ChildItem .\\*.txt | Foreach-Object {Compare-object $prime (Get-Content $_.FullName)} compares the .txt files in the current folder to masterfile.txt if the line is in both files it's ignored, if it's in the master but not the comparison file is outputs <= and if it's in the comparison but not the master file it outputs => there's probably a way to filter it so it only outputs the => results but this is just me doing some quick googling whilst bored and running on fumes.
Cheers guys, I hadn't given the powershell route much of a go as I figure it would likely be more involved but having noticed diff is an alias for Compare-Object, I figured it was worth a play and have come up with something which does the trick. Pretty much what RedFlames is working towards but output a bit more info and filters the results. I'm not too bad with Powershell most of the time, think last night it was a little late for my braincells to be engaging properly as it seemed a much better task yesterday then when I took another look this morning. This is what I ended up using: Code: $InputItems = Get-ChildItem -File -Path "C:\temp\nsclient\source\" $SourceFile = [System.IO.File]::ReadAllLines("C:\temp\nsclient\nsclient-start.ini") ForEach ($InputItem in $InputItems){ $Compare = $Null $Compare = [System.IO.File]::ReadAllLines($InputItem.Fullname) $Results += (Compare-Object $SourceFile $Compare | Where {$_.SideIndicator -eq "=>"}) | ForEach { $MissorDiff = $Null If ($SourceFile -match $_.InputObject.Split("=")[0]){ $MissorDiff = "Diff" } else { $MissorDiff = "Missing" } [pscustomobject]@{ SourceFile = $InputItem.Name Status = $MissorDiff Line = ($Compare | Select-String -Pattern $_.InputObject -SimpleMatch).LineNumber Data = $_.InputObject } } } $Results $Results | Export-CSV -NoClobber -NoTypeInformation -Path "C:\temp\nsclient\ns_updates.csv"
My brain wasn't braining especially well, but it was 3am and i was bored... i was just confident it was possible with pwsh [and thus not needing to faff about with WSL, as handy as it can be]