-1

I want find these files :

  • smart users04.csv
  • smart users07.csv

when I enter this:

find . -type f -regex "\bsmart\susers\d{2}\.csv\b"

It returns with nothing

Cactus'as
  • 70
  • 10
Sam
  • 39
  • 1
  • 10
  • Only the \b is valid for any of find's regextype's; \s and \d aren't in any of them, as far as I can see in the GNU find info pages. –  Jul 14 '19 at 21:52
  • Also see [How to tell find command to escape space characters in file names?](https://stackoverflow.com/q/42483587/608639), [How do I use find when the filename contains spaces?](https://unix.stackexchange.com/q/81349), [How can I search for files in directories that contain spaces in names, using “find”?](https://stackoverflow.com/q/25363070/608639), [find with spaces in filename](https://stackoverflow.com/q/12646124/608639), etc. – jww Jul 14 '19 at 21:53
  • @Roadowl is there any way to match these file names? I tried Grep but It took long time – Sam Jul 14 '19 at 22:01
  • 1
    `find . -type f -regex ".*smart.users..\.csv"` –  Jul 14 '19 at 22:02
  • 1
    Or, alternatively: `find . -type f -regex ".*smart.users[0-9][0-9]\.csv"`. –  Jul 14 '19 at 22:04
  • Or: `find . -type f -regextype egrep -regex ".*smart.users[[:digit:]]{2}\.csv"`. –  Jul 14 '19 at 22:06
  • 1
    Or even `find . -type f -regextype posix-extended -regex '.*\bsmart users[0-9]{2}\.csv\b'` ;D ... interesting point is that even **if** any of the regextypes knew \d it would still fail because as a minimum output there's always the leading `./`, which doesn't match the wordboundry requirement. – tink Jul 14 '19 at 22:06
  • Actually, my previous can be shorter: `find . -type f -regextype egrep -regex ".*smart.users[[:digit:]]{2}.csv"`. –  Jul 14 '19 at 22:07
  • @tink actually the word boundary worked with your example it matched with smart users04.csv and smart users07.csv but didnt match with ssmart users09.csv – Sam Jul 14 '19 at 23:15
  • also `find . -type f -regex ".*\bsmart.users[0-9][0-9]\.csv\b"` worked with the word boundary – Sam Jul 14 '19 at 23:16
  • @SamNano, well, yes. But it **won't** work without the `.*` before the word boundary – tink Jul 15 '19 at 00:39

2 Answers2

1

See comments to question ;)

find . -type f -regextype posix-extended -regex '.*\bsmart\s+users[0-9]{2}\.csv\b'
tink
  • 14,342
  • 4
  • 46
  • 50
  • 1
    `find . -type f -regextype posix-extended -regex ".*\bsmart users[0-9]{2}\.csv\b" | cut -c 3-` that will give me result beginning from smart without `./ ` – Sam Jul 15 '19 at 20:47
  • @SamNano Or, instead of invoking a second tool, just do `find . -type f -regextype posix-extended -regex ".*\bsmart users[0-9]{2}\.csv\b" -printf "%f\n"` =) – tink Jul 15 '19 at 21:10
0

Try this:

find . -type f -regex ".*smart users..\.csv"

or:

find . -type f -regextype egrep -regex ".*smart.users[[:digit:]]{2}.csv"

or even:

find . -type f -regextype egrep -regex ".*smart users[[:digit:]]{2}.csv".