How to find lines that contain ONLY lowercase using grep
12,676
Solution 1
You can use anchors in your regex for egrep
:
egrep '^[[:lower:]]+$' file
This egrep
will only find lines that have only lowercase letters in the (not even space is allowed).
Solution 2
This will match and exclude lines that contain something else besides a-z
.
cat file.txt | grep -v '[^[:lower:]]'
If you need to allow symbols too (this example allows !
, +
, ,
):
cat file.txt | grep -v '[^[:lower:]!+,]'
Author by
user3531263er
Updated on June 05, 2022Comments
-
user3531263er almost 2 years
I am new to bash and am learning to use grep.
grep ^[a-z] file.txt
will show all the lines that begin with lowercase
grep [a-z] file.txt
all lines with lowercaseCan't figure out how to show lines with ALL lowercase, can anyone help?