We have answer of your question!

100% solved queries, no empty question

Question: Remove anything after . (dot). Including dot


0

subdomain1.google.nl
subdomain1.subdomain2.google.com
subdomain1.facebook.com
subdomain1.subdomain2.facebook.com

How can i (by Powershell) remove the topleveldomain (TLD) so my results will be:

subdomain1.google
subdomain1.subdomain2.google
subdomain1.facebook
subdomain1.subdomain2.facebook
Question author Bsdanm | Source

Answer


1


You cat try regex patterns OR you could try this:

$string = 'subdomain1.google.nl'
[io.path]::GetFileNameWithoutExtension($string)

Output:

subdomain1.google

Actually! I was so curious about what would be the best perfomance wise method and guess what:

$results = @()
for ($i=1;$i -le 1000;$i++){
    $obj = New-Object PSObject
    $obj | Add-Member -MemberType NoteProperty -Name 'Execution #' -Value $([int]$i)
    $obj | Add-Member -MemberType NoteProperty -Name 'IOPath_Ticks' -Value $(Measure-Command -Expression {[System.IO.Path]::GetFileNameWithoutExtension('subdomain1.google.nl')} | Select -ExpandProperty Ticks)
    $obj | Add-Member -MemberType NoteProperty -Name 'Regex_Ticks' -Value $( Measure-Command -Expression {'subdomain1.google.nl' -replace '\.[^.]*?$'} | Select -ExpandProperty Ticks)
    $results += $obj
}

Average

$results  |  Measure-Object -Property IOPath_Ticks  -Average

Count    : 1000
Average  : 129,978
Sum      : 
Maximum  : 
Minimum  : 
Property : IOPath_Ticks

$results  |  Measure-Object -Property Regex_Ticks  -Average
Count    : 1000
Average  : 364,56
Sum      : 
Maximum  : 
Minimum  : 
Property : Regex_Ticks

Sum

$results  |  Measure-Object -Property IOPath_Ticks -Sum
Count    : 1000
Average  : 
Sum      : 129978
Maximum  : 
Minimum  : 
Property : IOPath_Ticks

$results  |  Measure-Object -Property Regex_Ticks -Sum
Count    : 1000
Average  : 
Sum      : 364560
Maximum  : 
Minimum  : 
Property : Regex_Ticks

So, as you can see when you need to process a big number of records usage of .NET Classes would do best compare to regexes

Answer author Kirill-pashkov

Tickanswer.com is providing the only single recommended solution of the question Remove anything after . (dot). Including dot under the categories i.e powershell , split , . Our team of experts filter the best solution for you.

Related Search Queries:


You may also add your answer

Thanks for contributing an answer to Tick Answer!