Get contents before a colon

This is what cut is for:

$ cat file
help.helloworld.com:latest.world.com
dev.helloworld.com:latest.world.com
foo:baz:bar
foo

$ cut -d: -f1 file
help.helloworld.com
dev.helloworld.com
foo
foo

You just set the delimiter to : with -d: and tell it to only print the 1st field (-f1).


Or an alternative:

$ grep -o '^[^:]*' file
help.helloworld.com
dev.helloworld.com

This returns any characters beginning at the start of each line (^) which are no colons ([^:]*).


Would definitely recommend awk:

awk -F ':' '{print $1}' file

Uses : as a field separator and prints the first field.