Artificial intelligent assistant

grep for capital words I have a file that has declarations in it with capital words, something like: public final Foo BAR; these declarations are not all uniform. Is there a way for me to grep out just the capital lettered words from the line? I know how to find lines that have capital letters in them, but thats not what I want. I want only the matching capital lettered word. Thanks!

Actually with the `-o` switch, GNU `grep` returns only what it has matched. How about:


grep -oP "\w*[A-Z]+\w*" yourfile.txt


Note that this regex will match words with capital letters _anywhere_ in them, not necessarily the beginning. You should tune it to meet your needs if they differ.

As pointed out below, this might not be the most portable of solutions. A portable alternative in Perl is


perl -nE 'say $1 while /(\w*[A-Z]+\w*)/g' yourfile.txt

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 3c80bc746abd9e1e0d044cdf8c652763