通过Bash ShellScripting从url列表中提取父域/子域名

时间:2015-10-01 10:36:19

标签: bash dns extract

我有这样的网址列表:

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

1 个答案:

答案 0 :(得分:2)

您可以使用awk -F/ '{sub(/^www\.?/,"",$3); print $3}' yourfile

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

<强>测试

Set shapeName = Selection