I am trying to figure out the best method to accomplishing this task, where I have a directory that has multiple files with varying file name formats, and I need to parse out those files that have a date in the file name (format of %F, or YYYY-MM-DD) from those that don’t, then iterate through each of them using a mix of a for loop and a case loop to segregate between files that have a date in the file name and those that don’t. Pseudo code is as follow:
#!/bin/bash
files=`ls`
for file in $files; do
# Command to determine whether $file has a date string
case (does variable have a date string?) in
has) # do something ;;
hasnt) # do something else ;;
esac
done
What is the best command to plug in for the comment, and then easiest way to execute such a case statement based off the command?
Given your original code, you can do
Or as @matchw recommends, you can use that pattern in a find
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.