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
Solved

Text file compare in powershell

Posted on 2013-06-19
2
381 Views
Last Modified: 2013-06-19
I have two text files..  i need to compare that text files with powershell. Please help me.

File 1  having below contents

01hw1
01hw2
01hw3
01hw4

File 2 having below contents

01hw1
01hw3
01hw5
01hw6


and i need  output like

Added entries :

01hw5
01hw6

Deleted entires:

01hw2
01hw4
0
Comment
Question by:aarun_tcs
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39259129
cls
$files1 = gc c:\temp\test\1.txt
$files2 = gc c:\temp\test\2.txt
$groups = Compare-Object $files1 $files2 | Group-Object -Property SideIndicator
Write-Output "Added Entries"
$groups[0].Group | %{Write-Output $_.inputobject}
Write-Output "" 
Write-Output "Deleted Entries"
$groups[1].Group | %{Write-Output $_.inputobject}

Open in new window

0
 

Author Comment

by:aarun_tcs
ID: 39259172
Thanks alot.. it works..
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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

839 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