1

Normally, I would ask a professor or classmate this, but as it's a Saturday and everyone is gone. I have to find a file in a directory that has five digits in a row somewhere in the file name. They don't have to be ascending or descending digits.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Irish Jet
  • 19
  • 2

2 Answers2

5

Wildcards (or globs) can accomplish this, with a numeric range:

ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

This tells the shell to look in /path/to/directory for filenames that start with:

  • * -- anything (or nothing)
  • [0-9] -- a digit
  • (four more digits)
  • * -- and ending in anything (or nothing)

That list of filenames is then passed to ls to list them.

More expansively, bash also allows character classes as wildcards, so if you have numbers in your language that aren't covered by [0-9], you could use:

ls -d *[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]*
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
-1

I have achieved by below method and i worked fine

find . -maxdepth 1  -type f| sed "s/\.\///g"| awk -F "." '{print $1}'|sed '/^$/d'| awk '/[0-9]/{print $0}'| awk '{print $1,gsub("[0-9]",$1)}'| awk '$2 == 5 {print $1}'