After some searching, I found a grep command that will find words containing capital letters, and list them without duplicates:

grep -hoP "\w*[[:upper:]]+\w*" * | sort -u

However, when it comes to words that contain characters such as ê, it seems that grep returns the word only up to that character, ignoring the character and anything afterward. My text is encoded as UTF-8, and I'm guessing the problem lies in my search criteria.

Is there a simple solution, for one who knows next to nothing about grep?

  • That does indeed work for the remaining characters in a word. Thanks. As you supposed, though, it does not work when the first letter is a special character. It likely won't be a problem in my case, though if there is a way to detect them all, that will be even better.
    – user182238
    Commented Apr 6, 2019 at 4:39
  • Not sure what happened to the comment and link that someone posted, but I've been playing around with the suggestions therein, and have had some success with this: grep -hoPw "\p{Lu}+\p{L}*" * | sort -u
    – user182238
    Commented Apr 6, 2019 at 4:54
  • can you give me some samples so that I can have a test, please? Commented Apr 6, 2019 at 6:39
  • I do wonder if this is just a matter of setting the right locale. Setting the locale to ISO-8859-1 works for me, you can check this online
    – iruvar
    Commented Apr 6, 2019 at 18:54

1 Answer 1


You can use grep with -P that enables Perl regexp capabilities and then specify your unicode characters range as a class of characters like below as example (find your language Unicode to replace in character class below).

grep -oP '\w*[\x00-\x99]+\w*' infile

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .