Find Duplicate character in each line

Welcome Forums General PowerShell Q&A Find Duplicate character in each line

This topic contains 4 replies, has 5 voices, and was last updated by

 
Senior Moderator
2 weeks, 3 days ago.

  • Author
    Posts
  • #174169

    Participant
    Topics: 41
    Replies: 41
    Points: 23
    Rank: Member

    Hi,
    I have a output file with following data:
    URL
    http://cool1.kalyan.com/asp1
    http://test.kalyan.com/asp1
    http://cool1.kalyan.com/asp10
    http://care.kalyan.com/asp2
    http://cool1.kalyan.com/asp15

    Need to find duplicate strings before ".kalyan.com" and out the complete line to a new file. Tried few options, but most of the time no luck. Can soemone please help me on this?

    -Kalyan

  • #174175

    Participant
    Topics: 1
    Replies: 1529
    Points: 2,587
    Helping Hand
    Rank: Community Hero

    Tried few options, but most of the time no luck.

    You will have to be more specific. What have you tried so far? What does "most of the time no luck" mean? Please show your code (format it as code using the code tag button on the editor window (pre) ).
    Thanks
    If you get error messages you should post these as well (formatted as code as well). A lot of times there's already a hint or even the solution for the error inside the error message.

  • #174181

    Participant
    Topics: 20
    Replies: 32
    Points: 160
    Helping Hand
    Rank: Participant

    Use excel > apply conditional formatting > filter out them as per formatting, copy it paste into new file. Job will be done in a minute. Enjoy..

  • #174427

    Participant
    Topics: 6
    Replies: 78
    Points: 143
    Helping Hand
    Rank: Participant

    For the sake of doing it in Powershell:

    $strs = (
    "http://cool1.kalyan.com/asp1",
    "http://test.kalyan.com/asp1",
    "http://cool1.kalyan.com/asp10",
    "http://care.kalyan.com/asp2",
    "http://cool1.kalyan.com/asp15"
    )
    $regex = [regex]::new("(?< =http:\/\/)(.*)(?=\.kalyan\.com)")
    $strs = $strs |
    Sort-Object
    for ($i = 0; $i -lt $strs.Count; $i++) {
    $current=$regex.match($strs[$i]).Value
    if (
    ($current-eq $($regex.Match($strs[$i+1]).Value)) -or
    ($current -eq $($regex.Match($strs[$i - 1]).Value))
    )
    {
    $strs[$i]
    }
    }
  • #174469

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    May be like this

    $PropertyList = @{E={ $null = $_ -match 'http://(.+)\.kalyan.+';$matches[1]};L='Child'},@{E={$_};L='Content'}
    Get-Content -Path C:\Temp\TestUrl.txt | Select-Object -Property $PropertyList | Sort-Object -Unique -Property Child
    
  • You must be logged in to reply to this topic.