How to find strings containing ONLY lowercase using grep

I am new to bash and am learning to use grep.

grep ^[a-z] file.txtwill display all lines starting with lowercase grep [a-z] file.txtall lines with lowercase letters

Unable to figure out how to show strings with all lowercase letters, can anyone help?

+4
source share
2 answers

You can use anchors in your regex to egrep:

egrep '^[[:lower:]]+$' file

This egrepwill find lines with only lowercase letters in (free space is not even allowed).

+5
source

, - , a-z.

cat file.txt | grep -v '[^[:lower:]]'

( !, +, ,):

cat file.txt | grep -v '[^[:lower:]!+,]'
+1

Source: https://habr.com/ru/post/1538557/


All Articles