Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Looking for a script to compare 3 text files and run a command in case they match

Hi,
I'm looking for a script (could be vb\power shell\batch) to compare between 3 text files, they only have a numeric value in them, in case all files match, then run a command

Any advise please?
0
johnnyjonathan
Asked:
johnnyjonathan
1 Solution
 
Martin TarlinkNetwork Systems AdministratorCommented:
Go ahead and use DiffMErge software it is nice GUI
http://www.sourcegear.com/diffmerge/
0
 
Vipin VasudevanCommented:
Please try this

Note sure what really required, from your question a you might looking for this, or you can derive the one you require from this
================================================================
$a=get-content .\files1.txt
$b=get-content .\files2.txt
$c=get-content .\files3.txt

$first = Compare-Object $a $b
$last = Compare-Object $a $c

if ($first -eq $Null -and $last -eq $Null)
{

            Write-Host "All file match"
            #{Execute your Command here}
}

elseif ($first -eq $Null)
{

Write-host "last two files not matching"
}
else       
{
Write-host "First two file not matching"
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0
 
Bill PrewCommented:
Here's a simple way to do it with just a BAT file script.

@echo off
setlocal

set File1=file1.txt
set File2=file2.txt
set File3=file3.txt

if not exist "%File1%" exit /b
if not exist "%File2%" exit /b
if not exist "%File3%" exit /b

fc "%File1%" "%File2%" >NUL && (
  fc "%File1%" "%File3%" >NUL && (
    echo Files match!
    REM run your command here
  )
)

Open in new window

~bp
0
 
johnnyjonathanAuthor Commented:
Perfect!
Thank you!
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now