1

I have a.txt and b.txt. A.txt contains {2b,3c,5e,8h}, B.txt contains {1a,2b,3c,4d,5e,6f}

I would like to compare those two files, and out put only what a.txt have,i.e. "8h".

I have tried Compare-Object command. But it gives out the differences. Please help

0

1 Answer 1

1

Given that the data is formatted exactly as above, you can use:

$a = '{2b,3c,5e,8h}'
$b = '{1a,2b,3c,4d,5e,6f}'

Compare-Object -ReferenceObject  $a.Trim('}', '{').Split(',') -DifferenceObject $b.Trim('}', '{').Split(',') | Where-Object {$_.SideIndicator -eq '<='}

Of course you will need to use Get-Content to read the contents of your file into $a and $b

Sign up to request clarification or add additional context in comments.

1 Comment

@Han please mark it as the answer if it helped you, so others can benefit as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.