I have a file that contains some text like:
aaa.co
bbb.com
ccc.net
sss.co.uk
I need to extract the *.co.* and *.com.* and put them in another file. I used the following to extract the *.com.* but how can I make extracting *.com.* and *.co.* in one command instead of performing them separately ?
egrep -io '[a-z0-9\-]+\.com(\.[a-z]{2})?' input.txt | sed -e 's/www.//' | sort | uniq >output.txt
Input file example:
aaa.co
bbb.com
ccc.net
sss.co.uk
Result file:
co
com
just make the m in com optional
edit:
you could also drop sed and uniq
edit:
another way to loose sed and uniq