I am trying to extract and clean the domains from a list of URLs. I read the post
How to extract domain name from url?
So far I can do this
$ URI="http://user:pw@example.com:80/"
$ echo $URI | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'
example.com
But in my list of URLS there are also some cases like below
example1.comDNT:
example2.comContent-Length:
I want to have output as below
example1.com
example2.com
Can I use python to solve this
Any advice would be appreciated
Thanks alot
Could you try this:
echo $URI | awk -F'http://user:pw@' '{print $2}' | sed 's/\.com.*/.com/'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.