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.
`basename` command is used to read the file name without extension from a directory or file path. Here, NAME can contain the filename or filename with full path. SUFFIX is optional and it contains the file extension part that the user wants to remove. `basename` command has some options which are described below.
So basically, $# is a number of arguments given when your script was executed. $* is a string containing all arguments. For example, $1 is the first argument and so on. This is useful, if you want to access a specific argument in your script.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With