Seems like this is rather simple, but I\'m having trouble.
I have a text document that looks, for example, like this:
This is a
TEXT DOCUME
To complement Zbynek Vyskovsky - kvr000's helpful answer:
grep
's -E
option allows use of extended regular expression, which includes quantifier +
to mean one or more, which simplifies the solution:
grep -Eo '\<[[:upper:]]+\>' Untitled.txt
Also, as mentioned in Benjamin W.'s answer, -w
can be used to match on word boundaries without having to specify it as part of the regex:
grep -Ewo '[[:upper:]]+' Untitled.txt
Note, however, that -w
is a nonstandard option (but both BSD/OSX and GNU grep
implement it).
As for egrep
: it is nothing more than an (effective) alias of grep -E
, which, as stated, activates support for extended regular expressions, but the exact set of features is platform-dependent.
Additionally, only GNU grep
supports the -P
option to support PCREs (Perl-Compatible Regular Expression), which offer even more features and flexibility.