Like grep only words that are made up of capital symbols

I have a write grep problem that should grep only those lines that have a word consisting only of capital characters.

For example, I have a file: file1.txt

Abc AAA
ADFSD
F
AAAAx

And the conclusion should be:

Abc AAA
ADFSD
F

Thanks for any advice.

+4
source share
7 answers

This egrep should work:

egrep '\b[A-Z]+\b' file
+7
source

You can simply use:

grep -E '\b[[:upper:]]+\b' file1.txt

That is, find whole words consisting of only capital letters.

+6
source
 grep -w '[^ ]*[A-Z]\+'  file1.txt
+1

, ASCII, \p{Lu} [A-Z]:

grep -P '\b\p{Lu}+\b' file

LONDON 
Paris
MÜNCHEN Berlin

LONDON
MÜNCHEN Berlin

, , , , @Skippy-le-grand-gourou, egrep [A-Z] , \p{Lu}, " 2017 , , ẞ " "

+1
grep -oP '\b[A-Z0-9_]+\b' file1.txt  

, //_ (, HELLO, NUMBER10, RLIMIT_DATA).

eDw.

+1

GNU grep POSIX, :

grep -e '[[:upper:]]' file1.txt

0

grep '\ < [A-Z] * > ' file1.txt

0

All Articles