Solved

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

Posted on 2014-10-21
4
174 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
Comment Utility
Go ahead and use DiffMErge software it is nice GUI
http://www.sourcegear.com/diffmerge/
0
 
LVL 6

Expert Comment

by:Vipin Vasudevan
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
Perfect!
Thank you!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

10 Experts available now in Live!

Get 1:1 Help Now