Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to compare two text or csv files.

$
0
0

Hi Expert,

I am stuck with my script. It gives me no error but i am not getting desired output.

I have two files text file or csv file. It depends upon me which file i required i have both option my data is in string value and single column only so, it can be text or csv whichever is required. I have to compare the file each line with another file. No matter data is located on which line. It will have to compare every line every time. I tried many times but i am not getting desired output. I tried to compare it as text or csv but all the times it is not giving me output as require.

Here is my code :(

$csv2 = "C:\Users\Desktop\Log\Threat_report.01232014195755.txt" 

$csv1 = "C:\Users\Desktop\Log\Threat_report.txt"

Compare-Object -ReferenceObject (get-content -path $csv1) -DifferenceObject (get-content -path $csv2)| export-csv "C:\Users\Desktop\Log\Threat_Report.csv" -NoTypeInfo

sample data File 1

 - File ONTAP_ADMIN$\vol\ABCDEF\Groupdata$\Central_Resource_Publish\Temp data Menu\~$temp aResource Menu.xlsm 
ONTAP_ADMIN$\vol\ABCDEF\Groupdata$\Central_Resource_Publish\Temp data Menu\~$temp Rsfsesource Menu.xlsm
Sample data file 2
ONTAP_ADMIN$\vol\ABCDEF\Groupdata$\Central_Resource_Publish\Temp data Menu\~$temp Nomenu Menu.xlsm 

ONTAP_ADMIN$\vol\ABCDEF\Groupdata$\Central_Resource_Publish\Temp data Menu\~$temp aResouserce Menu.xlsm 

 

ONTAP_ADMIN$\vol\ABCDEF\Groupdata$\Central_Resource_Publish\Temp data Menu\~$temp Rsfsesource Menu.xlsm

 

ONTAP_ADMIN$\vol\ABCDEF\Groupdata$\Central_Resource_Publish\Temp data Menu\~$temp Rsfsesouaferce Menu.xlsm
When i compare the file script is working fine but when i shuffle the it show me entire data in csv file. It seems like it is only comparing line 1 to line 1, line 2 to line 2 so on. It doesn't check like line 1 to line 1, 2, 3 , 4 ...
Please advise me how to resolve this issue.

Viewing all articles
Browse latest Browse all 6937

Trending Articles