Q:

remove whitespace from piped output

In a textfile i have some tags with the notation :foo. To get an overview of my tags in the file, I want to get a listing of all this tags. 
This is done via 
grep -o -e ":[a-z]*\( \|$\)" file.txt | sort |  uniq

Now I get duplicates because of the whitespace or newline character at the end. 
:movie  <-- only newline
:movie  <-- whitespace and newline
:read
:read 

I want to avoid the duplicates. But I could not figure out how. I tried with | tr -d '[:space:]', but this leads only to a concatenation of all pipe output... 
Example of the file.txt
Avengers: Infinity War :movie
Yojimbo 1961 :movie nippon

A:

Some test lines (there is a space after the first :space, you can see it if you highlight the data with your mouse):
$ cat file
with :space 
with :space too
without :space
test: this

With grep, sort and uniq:
$ grep -o ":[a-z]\+" file | sort | uniq 
:space

With awk (well, gawk and mawk at least):
$ awk 'BEGIN{RS="[" FS "|" RS "]+"}/:[a-z]/&&!a[$0]++' file
:space

Each word is its own record and we pick the first instance of every colon-starting word. RS="[" FS "|" RS "]+" could be written otherwise but it is in this form to emphasize any combination of FS and RS.

