Hands-on task
Domains from URLs
/root/urls.txt contains a list of URLs. Extract only the domain names (without http://, without the path) into /root/domains.txt.
- sed
- grep
- regular expressions
- negated class
- url
Hands-on task
/root/urls.txt contains a list of URLs. Extract only the domain names (without http://, without the path) into /root/domains.txt.
This task is about extracting the part of a string between known boundaries: you need to cut off the scheme (http:///https://) and the path, leaving the host. One approach is a substitution in sed -E: capture the host in a group and replace everything else with its contents. The host is described by the negated class [^/]+, which greedily takes everything up to the first slash of the path. The optionality of the letter s in the scheme is set by the ? quantifier. The alternative is grep's PCRE mode with a lookbehind (?<=://), which doesn't include the separator in the result and does without a capture group.