Regular expression date on solaris

1

I need to find files whose extension ends with a date format YYYYMMDD , in Linux I have the following command:

find . -regextype posix-extended -regex './.*.([0-9]{4})(0[1-9]|1[012])([12][0-9]|[0-9]|3[01]){2}'

But Solaris does not work, and tried in different ways but always ends in error.

    
asked by Maca 27.03.2018 в 17:09
source

1 answer

1

You're very close, just a few tweaks in the regular expression are missing:

find . -regextype posix-extended -regex '.*\..*[0-9]{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])'


Description:

.*\..*[0-9]{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])
  • .* ::: any number of characters from the beginning
  • \. ::: a literal point (it has to be escaped with the bar, otherwise it matches any character)
  • .* ::: any number of characters from the point forward
  • [0-9]{4} ::: 4 digits (year)
  • (0[1-9]|1[0-2]) ::: a zero followed by 1 to 9, or a 1 followed by 0 to 2 (month)
  • (0[1-9]|[12][0-9]|3[01]) ::: 0 followed by 1 to 9, or 1 or 2 followed by 0 to 9, or a 3 followed by a 0 or 1 (day)


Alternatively, you may not want to complicate yourself with so much validation, and just look for a file ending in 8 digits:

.*[0-9]{8}
    
answered by 28.03.2018 в 23:43