grep whole words made of only uppercase letters

前端 未结 5 1960
[愿得一人]
[愿得一人] 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:19

    The example output shows multiple space separated uppercase words on the same line, which can be achieved with

    $ grep -ow '[[:upper:]][[:upper:][:space:]]*[[:upper:]]' infile
    TEXT DOCUMENT
    SOME
    BUT NOT
    ALL CAPS
    

    Any sequence starting and ending with an uppercase character, and uppercase characters or whitespace between them. -o returns the matches only, and -w makes sure that we don't match something like WORDlowercase.

提交回复
热议问题