Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh, matching any n digits 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

I can do list a 3 digits files in that way:

ls -ld [0-9][0-9][0-9]


but following with number doesn't work (example for longer name files):

ls -ld {15}[0-9]





 
If I understand your problem correctly (i.e. looking for files which have a specific length and consist only of numbers) this would be a possible solution - in this example desired length is 4 characters

$ ls
1 1234 2 23456 3456 45 45678 567 bl23 bluh
12 12345 234 3 34567 456 5 5678 blah
123 1bla 2345 345 4 4567 56 56789 bloh
$ find /home/tom/Dokumente -type d -regextype posix-egrep -regex ".*/[^/][0-9]{3}"
/home/mrjazz/Dokumente/5678
/home/mrjazz/Dokumente/4567
/home/mrjazz/Dokumente/2345
/home/mrjazz/Dokumente/3456
/home/mrjazz/Dokumente/1234

so files blah, bloh, bluh, and also 1bla, bl12 are not found
 
What about this (for 15 digits) ?
ls -ld [0-9]* | egrep ' [0-9]{15}$'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hello

I have a solution which is fine for me:
ls|grep -E '^[[:digit:]]{15}$'


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top