Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • MacOS 10.9.5 does not seem to have the -c option to stat. Commented Oct 29, 2015 at 3:33
  • My bad. The equivalent seems to be stat -f %m -t %F "$file". Sorry, I can't test it. Commented Oct 29, 2015 at 7:14
  • With the change in the stat as per your comment, things seem to execute but no output for all test cases. But, what is the "$file" =~ ([0-9]{8}).txt$ doing? Commented Oct 29, 2015 at 7:46
  • It looks for the 8 digits followed by .txt at the end of the filename. The parentheses () captures the 8 digits part, and you can find it in ${BASH_REMATCH[1]}. Commented Oct 29, 2015 at 7:58
  • If your bash doesnt work with if [[=~]] you can try the basic if filedate=$(expr "$file" : '.*-\([0-9]*\).txt') and then replace ${BASH_REMATCH[1]} by $filedate. Commented Oct 29, 2015 at 8:08