从 Shell 中的文件中提取域名 [英] Extract domain names from a file in Shell
本文介绍了从 Shell 中的文件中提取域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,它的内容是一些 URL 的列表,
我想从 bash 中的这个 URL 列表中提取域名
示例:
I have a file and it's content is a list of some URLs,
I want to extract the domain names from this list of URLs in bash
Example:
sub1.domain.com
domain3.com
sub5.domain.ext
subof.subdomain.domainx.ex2
我只想从这个列表中提取域名
我该怎么做?
谢谢
I want to extract just domain names from this list
How can I do this?
Thank you
推荐答案
可以使用grep
:
grep -Eo '[^.]+.[^.]+$' file.txt
示例:
$ cat file.txt
sub1.domain.com
sub2.domains2.com
domain3.com
sub5.domain.ext
subof.subdomain.domainx.ex2
$ grep -Eo '[^.]+.[^.]+$' file.txt
domain.com
domains2.com
domain3.com
domain.ext
domainx.ex2
请注意,这将为 www.google.co.uk
返回 co.uk
.
Note that this will return co.uk
for www.google.co.uk
.
这篇关于从 Shell 中的文件中提取域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文