Say I have a list of the following files in my current dir:
lab1.jav
mytst2
pie.c
prog2.c
tst3.ex
tst5:5.tlab2jav
lab2jav.ext
new.c
prog1.c
tst1
tst4.ex
c tst6:6123.tA7-tst.c
fred.txt
And I need to list the files with a total of say 7 letters for example. How would you do this? I tried to no avail:
ls | egrep -i '[a-z]{7}'
I think it's because the dots are in the way, is there a simple way of doing this?
It can be done this way:
ls | grep -E '^(\W*[0-9]*[a-zA-Z]){7}\W*[0-9]*$'
This includes cases when the first and the last character is a digit or a non alphanumeric char.
Or shorter
ls | grep -Ei '^([^a-z]*[a-z]){7}[^a-z]*$'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments