awk '/user/ {print $1 }' /etc/userdomains | sed 's/://'
the format of /etc/userdomains is
domain.tld: user
otherdomain.tld: otheruser
awk '/user/ {print $1 }' /etc/userdomains | sed 's/://'
the format of /etc/userdomains is
domain.tld: user
otherdomain.tld: otheruser
The easiest way is to set the field separator to ":"
awk -F":" '$2~/user/{print $1}' /etc/userdomains
And if you want to check for exact username,
awk -F"[ \t]*:[ \t]*" '$2=="user"{print $1}' /etc/userdomains
You can use gsub in awk to remove all :s in the string.
awk '/user/ {gsub(":", ""); print $1}' /etc/userdomains
awk has a sub(regexp, replacement, target) function that finds the first occurrence of regexp in target ($0 by default) and replaces it with replacement (in-place):
awk '/user/ {sub(/:/, ""); print $1}' /etc/userdomains
You could use tr instead of sed:
awk '/user/ {print $1 }' /etc/userdomains | tr -d ":"
Though I don't see how that's better than just using awk (nor do I see what's wrong with sed).