I have a text file:
1 2 4 5 6 7 1 3 5 6 7 8 1 2 3 4 5 6 1 2 4 5 6 7
Here the first and last line are close. I have many double line files. I need to remove all duplicates.
It all seems very complicated. It is as simple as:
gc $filename | sort | get-unique > $output
Using actual file names instead of variables:
gc test.txt| sort | get-unique > unique.txt
To get unique strings:
PS > Get-Content test.txt | Select-Object -Unique 1 2 4 5 6 7 1 3 5 6 7 8 1 2 3 4 5 6
To remove a duplicate
PS > Get-Content test.txt | group -noelement | ` where {$_.count -eq 1} | select -expand name 1 3 5 6 7 8 1 2 3 4 5 6
If the order is not important:
Get-Content test.txt | Sort-Object -Unique | Set-Content test-1.txt
If order is important:
$set = @{} Get-Content test.txt | %{ if (!$set.Contains($_)) { $set.Add($_, $null) $_ } } | Set-Content test-2.txt
Try something like this:
$a = @{} # declare an arraylist type gc .\mytextfile.txt | % { if (!$a.Contains($_)) { $a.add($_)}} | out-null $a #now contains no duplicate lines
To set the contents of $ a to mytextfile.txt:
$a | out-file .\mytextfile.txt
$file = "C:\temp\filename.txt" (gc $file | Group-Object | %{$_.group | select -First 1}) | Set-Content $file
The source file now contains only unique lines
Already published options did not help me for some reason
Source: https://habr.com/ru/post/898373/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/898368/how-to-add-a-css-class-to-a-z3cform-button&usg=ALkJrhi4e2VOqPWHKYoyMWtuXDsQ50mx_wEntity Framework One-to-Many Insert - Foreign Key Violation - c #Capturing a specific array element in Objective-C - objective-cRails 3.1 Mongoid has_secure_password - ruby-on-railsHow are UIApplication subclasses in Monotouch? - c #StructureMap error: there is no default value for the PluginFamily module - c #https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/898375/use-php-to-convert-jpegs-to-transparent-png&usg=ALkJrhgiSGB6CoTICl9me7ir-UpMFXv52wHow do I know when a class is an assistant or a service? - designFlush postgres data with indexes - indexingUsing cedet semantic wisent-ruby - ruby | fooobar.comAll Articles