0

I have two text files with a list of paths. They share some paths but they also have their own unique paths as well. Each path is on different line and there are thousands of lines on each txt file. What powershell command can I use to extract the paths unique to one of the files, lets say file2.txt and put those unique paths on a new text file? The paths put on the new text file should be completely unique to the new file so if file1.txt has the path C:\Build\2\11\s\Build\Api\Api.Entity\System.Web and file2.txt has the path C:\Build\2\11\s\Build\Api\Api.Search\CLM.Web.config then neither path should be put in the new text file

1

Use Compare-Object. Simplyfied demo:

> gc .\file1.txt
9
8
6
5
3
2

> gc .\file2.txt
1
2
4
5
7
8

> Compare-Object (gc .\file1.txt|sort) (gc .\file2.txt|sort)

InputObject SideIndicator
----------- -------------
1           =>
4           =>
7           =>
3           <=
6           <=
9           <=

You may select which unique items to filter by SideIndicator

> Compare-Object (gc .\file1.txt|sort) (gc .\file2.txt|sort)|? SideIndicator -eq '=>'

InputObject SideIndicator
----------- -------------
1           =>
4           =>
7           =>


> Compare-Object (gc .\file1.txt|sort) (gc .\file2.txt|sort)|? SideIndicator -eq '<='

InputObject SideIndicator
----------- -------------
3           <=
6           <=
9           <=
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.