So, I want to combine only the domain from the ether:
http://www.google.com/test/
http://google.com/test/
http://google.net/test/
The output should be for all 3: google
This code works for me only for .com
echo "http://www.google.com/test/" | sed -n "s/.*www\.\(.*\)\.com.*$/\1/p"
Output: 'google'
Then I thought it would be as easy as saying (com | net), but that does not seem true:
echo "http://www.google.com/test/" | sed -n "s/.*www\.\(.*\)\.(com|net).*$/\1/p"
Output: '' (nothing)
I was going to use a similar method to get rid of "www", but it seems that I'm doing something wrong ... (doesn’t it work with regex outside \ (\) ...)
source
share