Each field in a /etc/passwd line is separated by a colon, and the username is the first field, so you need to filter each line to only show the characters up to the first colon. Answer. grep is not even close to the best tool for doing this, but if you're required to use it, this will work: grep -oE '^[^:]+' /etc/passwd

4957