[英]Clean and extract domain name from URL
I am trying to extract and clean the domains from a list of URLs.我正在尝试从 URL 列表中提取和清理域。 I read the post
我看了帖子
How to extract domain name from url? 如何从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但是在我的 URLS 列表中也有一些情况如下
example1.comDNT:
example2.comContent-Length:
I want to have output as below我想要 output 如下
example1.com
example2.com
Can I use python to solve this我可以使用 python 来解决这个问题吗
Any advice would be appreciated任何意见,将不胜感激
Thanks alot非常感谢
Could you try this:你能试试这个吗:
echo $URI | awk -F'http://user:pw@' '{print $2}' | sed 's/\.com.*/.com/'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.