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

Viewing 4 reply threads
  • 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: 2
      Replies: 1758
      Points: 3,646
      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: 21
      Replies: 39
      Points: 214
      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: 108
      Points: 304
      Helping Hand
      Rank: Contributor

      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: 1163
      Points: 4,071
      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
      
Viewing 4 reply threads
  • The topic ‘Find Duplicate character in each line’ is closed to new replies.