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

Repeat duplicate

$
0
0

Hi powerShell,

Here is script:

$input = @(Get-Content H:\aa.txt |ForEach-Object {($_ -replace "\s+",",")} )

$repeating = @($input | ForEach-Object{$_.split(',')[1] } | Group )

$input | ConvertFrom-Csv -Header (1..4)|
            ForEach-Object {  $_.'3' = 'test';  $_ } |
            ConvertTo-Csv -NoTypeInformation |
            Select-Object -Skip 1 |
            ForEach-Object { $_ -replace '"','' }
           
$repeating = @($input | ForEach-Object{$_.split(',')[1] } | Group )

where aa.txt:
as aa
af aa
ag aa
ch bb
fe bb
fe cc
gh cc

My output looks good:
as,aa,test,
af,aa,test,
ag,aa,test,
ch,bb,test,
fe,bb,test,
fe,cc,test,
gh,cc,test,

and now i want to repeat duplicate count in element [1] so i figure it as below
$repeating = @($input | ForEach-Object{$_.split(',')[1] } | Group )

i have no idea how to execute like this:
aa 1
aa 2
aa 3
bb 1
bb 2
cc 1
cc 2

Any Idea?

Thanks

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles