How do you parse a filename in bash?

bash, cut, parsing, shell, tokenize

Solution

You can use the cut command to get at each of the 3 'fields', e.g.:

$ echo "system-source-yyyymmdd.dat" | cut -d'-' -f2
source

"-d" specifies the delimiter, "-f" specifies the number of the field you require

Problem

I have a filename in a format like: `system-source-yyyymmdd.dat` I'd like to be able to parse out the different bits of the filename using the "-" as a delimiter.

Original source