1

I am trying to execute this command

find /home/scratch/test_cases/deleted/2nmW1wDfb5/ -iregex '.*/moodys_munis_full_refresh_flat_file_\d+.zip' -type f

It cannot find any file but the file is there when I do ls

ls /home/scratch/test_cases/deleted/2nmW1wDfb5/moodys_munis_full_refresh_flat_file_2.zip

Result is

/home/scratch/test_cases/deleted/2nmW1wDfb5/moodys_munis_full_refresh_flat_file_2.zip
1
  • 1
    Try: -iregex '.*/moodys_munis_full_refresh_flat_file_[0-9]*\.zip' Commented Mar 1, 2018 at 16:12

1 Answer 1

1

Try:

find ... -iregex '.*[0-9]+.zip' -type f

instead. Or run

find -regextype --help
find: Unknown regular expression type '--help'; valid types are 'findutils-default', 'awk', 'egrep', 'ed', 'emacs', 'gnu-awk', 'grep', 'posix-awk', 'posix-basic', 'posix-egrep', 'posix-extended', 'posix-minimal-basic', 'sed'.

to get a list of known -regextypes on your system, and try

find ... -regextype sed -iregex '.*[0-9]+.zip' -type f

and the other options, if you don't know, what which style stands for.

On my system, \d doesn't work with any of the options:

for rt in "findutils-default" "awk" "egrep" "ed" "emacs" "gnu-awk" "grep" "posix-awk" "posix-basic" "posix-egrep" "posix-extended" "posix-minimal-basic" "sed"
do 
   echo -n $rt" "
   find . -type f -regextype $rt -iregex '.*ro.*2\d+.scala'
   echo
done

findutils-default 
awk 
egrep 
ed 
emacs 
gnu-awk 
grep 
posix-awk 
posix-basic 
posix-egrep 
posix-extended 
posix-minimal-basic 
sed 

while rectangle braces are understood by about 50% of them:

for rt in "findutils-default" "awk" "egrep" "ed" "emacs" "gnu-awk" "grep" "posix-awk" "posix-basic" "posix-egrep" "posix-extended" "posix-minimal-basic" "sed"
do 
   echo -n $rt" "
   find . -type f -regextype $rt -iregex '.*ro.*2[0-9]+.scala'
   echo
done

findutils-default ./rot1-25.scala

awk ./rot1-25.scala

egrep ./rot1-25.scala

ed 
emacs ./rot1-25.scala

gnu-awk ./rot1-25.scala

grep 
posix-awk ./rot1-25.scala

posix-basic 
posix-egrep ./rot1-25.scala

posix-extended ./rot1-25.scala

posix-minimal-basic 
sed 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the reply! I tried with sed and [0-9]+ worked but then [0-9]{5} doesnt work. Since the option to enter file matching pattern will be available to users, they can enter any regex. Whay {5} doesnt work?
@Imran: Have you seen the for-loops to test the -regexp-types against a regex? Sometimes you have to mask \{5\}, some will not understand it at all. "egrep" works without masking, "sed" for example with masking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.