If I understand correctly what you want, it is to filter away clients with connections other than 'Purple' (only 'Green' in your example, but possibly other colours).
The following commands use grep
to remove lines with 'Purple', tr
to make one line and sed
to put line breaks before 'client' and finally grep
to remove remaining lines with 'connection' and to select only the desired piece of information for each client.
The whole information set:
< myfile grep -v 'Purple' | tr '\n' ' '| tr -s ' ' ' ' | sed "s/ client/\nclient/g" \
| grep -v 'connection'
The hostname and whatever listed behind:
< myfile grep -v 'Purple' | tr '\n' ' '| tr -s ' ' ' ' | sed "s/ client/\nclient/g" \
| grep -v 'connection' | grep -o 'hostname: .*'
Only hostname, which you wanted according to what I could read:
< myfile grep -v 'Purple' | tr '\n' ' '| tr -s ' ' ' ' | sed "s/ client/\nclient/g" \
| grep -v 'connection' | grep -o 'hostname: [^ ]*'
The other group (that should be filtered out) with hostname and connection other than 'Purple':
< myfile grep -v 'Purple' | tr '\n' ' '| tr -s ' ' ' ' | sed "s/ client/\nclient/g" \
| grep 'connection' | grep -o 'hostname: .*'