Solved

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

Posted on 2014-10-21
4
190 Views
Last Modified: 2014-10-22
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
Comment
Question by:johnnyjonathan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Expert Comment

by:Martin Tarlink
ID: 40394758
Go ahead and use DiffMErge software it is nice GUI
http://www.sourcegear.com/diffmerge/
0
 
LVL 6

Expert Comment

by:Vipin Vasudevan
ID: 40394813
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
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40395503
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
 

Author Closing Comment

by:johnnyjonathan
ID: 40397224
Perfect!
Thank you!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question