Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find lines that contain ONLY lowercase using grep

Tags:

regex

grep

bash

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 lowercase

Can't figure out how to show lines with ALL lowercase, can anyone help?

like image 231
user3531263er Avatar asked Jan 11 '23 17:01

user3531263er


1 Answers

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).

like image 55
anubhava Avatar answered Jan 18 '23 16:01

anubhava