Extract domain names from a file in Shell [closed]
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 You can use grep : grep -Eo '[^.]+\.[^.]+$' file.txt Example: $ 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 Note that this will return co.uk for www.google.co.uk .