# Removing Duplicate words from lines in a power shell

Hi

I am trying to find away to remove Duplicate words from a text file using Powershell

Name1 PC1234 PC1234 start Tue 2/17 6:53
Name2 PC5678 PC5678 start Tue 2/17 7:51

What I would like is

Name1 PC1234 start Tue 2/17 6:53
Name2 PC5678 start Tue 2/17 7:51

I have managed to get it working using the following but I would like to be able to open a .txt file remove the duplicate on all lines and right the content back to a new file.

$text= "Name1 PC1234 PC1234 start Tue 2/17 6:53"$text.Length
$text.remove(14)  Thank you of your help LVL 1 Asked: ###### Who is Participating? Commented: So the third column is always a copy of the second? This will remove the third column: Get-Content C:\Temp\in.txt | % {$_.Split(" ")[0..1+3..($_.Length -1)] -join " "} | Set-Content C:\Temp\out.txt  0 Senior Solution ArchitectCommented: Might not be a solution that your looking for, but the easiest way to accomplish this is in Excel and using the remove duplicate button. Will. 0 Author Commented: Hi oBda Almost there and I understand the$_.Split

How would I be able to get the code to ignore the 1st line in the text file.

Keep this text
Name1 PC1234 PC1234 start Tue 2/17 6:53
Name2 PC5678 PC5678 start Tue 2/17 7:51

Thank you

Si
0

Batchelor and DeveloperCommented:
$( Get-Content C:\Temp\in.txt | select -First 1 Get-Content C:\Temp\in.txt | select -Skip 1 | % {$_.Split(" ")[0..1+3..(\$_.Length -1)] -join " "}
) | Set-Content C:\Temp\out.txt

0

Author Commented:
Hi oBda and Qlemo

Thank you the solutions worked perfectly

Si
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.