grep whole words made of only uppercase letters

前端 未结 5 1999
[愿得一人]
[愿得一人] 2021-01-23 04:23

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

5条回答
  •  甜味超标
    2021-01-23 05:29

    An "old school" RE would be fewer characters:

    grep -o '[A-Z][A-Z]*' Untitled.txt

    It uses the -o option to Only print matching words and matches against uppercase A through Z.

    Adding -w to search words and -E to invoke the Extended regular expressions allows this one that is even shorter:

    grep -woE '[A-Z]+\>' Untitled.txt

提交回复
热议问题