Solved

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

Posted on 2014-10-21
4
184 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 53

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Batch/VBscript: import massively chedule task in windows task scheduler 15 45
powershell function location 6 39
Shutdown Inactive Server- Script 4 19
DFS-R questions 4 26
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.

770 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