I love the comment that someone dropped on the post. One could replace the first Ruby script by a one-liner: "cat /tmp/com.txt | awk '{ print substr($1, 1, length($1) -5) }' | uniq > domains.txt"
ruby -e "puts File.read('/tmp/com.txt').scan(/^[^.]+/).uniq"
Personally I almost never use any of the standard Unix tools like `awk` etc. since an equivalent Ruby script is almost always shorter and easier to write. (There are exceptions of course; and in really simple cases the standard tools will obviously still win.)
I think it's a shame that Ruby never really got popular as a general purpose scripting language, since it has that nice property that it's often as short as Perl while still being readable.