splitting inline to get website address

hi

I need some help/ideas/thoughts…

I have a file with website adresses (tabs from firefox)
what I want/need is to be able to split each line to extract the website address…

example lines are:

window #1/tab #17 Step-by-step SCCM 1511 Migration to New Hardware
window #1/tab #18 Complete SCCM 2012 SQL Install Guide Complete SCCM 2012 SQL Install guide

as you can see on line 2 it doesn’t just end after the address but has the window title…

Anyone have any ideas?

without more info, I’m only guessing, but this may be a starting point

get-content c:\temp\sites.txt | ? {$_ -match '\d https?:'} | % {
	$_.split(' ')[-1]
}

hi

just tried your oneliner… no result at all…

The code I ran is:

get-content C:\Users\mrt\AppData\Roaming\Mozilla\Firefox\Profiles\zzatbluv.default\opentabs-ARD-LT-MRT-20160420-0939.txt | ? {$_ -match '\d https?:'} | % { $_.split(' ')[-1]}

I’ve copy/pasted a complete file examples:

http://pastebin.com/Wr04dYPj

$pattern = [regex]"\s+(?'url'https*://[\w\./\-\%\?=\+&]+)\s*"
Get-Content -Path .\test.txt | foreach {
    if ($line -match $pattern)
    {
        $Matches['url']
    }
}

This seems to be a pretty good match for your sample text file.

hi Bob

thx… looks great…
I tried this:

$Path="C:\Users\mrt\AppData\Roaming\Mozilla\Firefox\Profiles\zzatbluv.default\" $file="opentabs-ARD-LT-MRT-20160421-1502.txt" $pattern = [regex]"\s+(?'url'https*://[\w\./\-\%\?=\+&]+)\s*" Get-Content -Path "$Path$File" | foreach { if ($line -match $pattern) { $Matches['url'] write-host $matches
}

}

but no results…

the get-content produces results…

i tried adding else {write-host $file}

but still nothing…

This works:
$pattern = [regex]“\s+(?'url’https*://[\w./-%?=+&]+)\s*”
Get-Content -Path d:\temp\test\test.txt | foreach-object {
if ($_ -match $pattern)
{
$Matches[‘url’]
}
}

You don’t need the write-host. And you would only use $matches[‘url’]. And since you didn’t tell us what you want to do with the data (write to screen, file, etc.) it is essentially demo code showing how to extract the data.

If you tell us more we can probably give you a more complete solution.

hi all…

thank you for the suggestions… It kindda stranded for a while but after a crash today I decided that now was the time…

I fiddled a lot with how to open all results in tabs but nothing worked … I ended up crashing my computer because it opened so many instances of firefox that the system halted…

finally I went the KISS way and did this:

& 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe' start-sleep 5 $pattern = [regex ]"\s+(?'url'https*://[\w\./\-\%\?=\+&]+)\s*" Get-Content -Path C:\Users\mrt\AppData\Roaming\Mozilla\Firefox\Profiles\rluonxjq.default\opentabs-ARD-LLT-MRT-20160815-1513.txt | foreach-object { if ($_ -match $pattern) { Start-Process $matches ['url'] } }

Powershell almost always has a real simple way to manipulate strings without ridiculous regex patterns.

As you said, KISS.

$text.split(’ ') -match ‘:’