Solved

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

Posted on 2014-10-21
4
180 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
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 52

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now