通过 Bash ShellScripting 从 url 列表中提取父 domain/subdomain 名称

Extract parent domain/subdomain name from a list of url through Bash ShellScripting

我有这样的 URL 列表:

http://example.com/sdfsdf/sdfsa
https://example2.com/53lasfd/asdfs
http://www.example3.com/asdfas/asdfasdf.php?=asdfa
https://subdomain.example4.com/index.php?id=sadfa
https://www.subdomain.example5.com/asdfas/asdfasd

我只需要提取没有 httphttpswww/:

之后的域(和子域)
exmaple.com
exmaple2.com
example3.com
subdomain.example4.com
subdomain.example5.com

您可以使用 awk,

awk -F/ '{sub(/^www\.?/,"",); print }' yourfile

测试:

$ awk -F/ '{sub(/^www\.?/,"",); print }' yourfile
example.com
example2.com
example3.com
subdomain.example4.com
subdomain.example5.com