TEMP line strips shortest possible rightside (%) '.'+anything (.*) - read: extension - and adds .mood
OUTF line pipes $TEMP value to sed which splits the whole path in 2 parts with the last /, effectively cutting it to path (\1) and filename (\2) parts. Then it glues them back with /. which effectively means the filename got prefixed with .
with -r parameter the picture is clearer
sed -r 's#(.*)/([^,]*)#\1/.\2#'
Why the filename part is matched by not-colon any number of times [^,]* - no idea.
Code:
$ i=/some/path/file.mp3
$ TEMP="${i%.*}.mood"
$ echo "$TEMP"
/some/path/file.mood
$ OUTF=$( echo "$TEMP" | sed -r 's#(.*)/([^,]*)#\1/.\2#' )
$ echo "$OUTF"
/some/path/.file.mood
the same behavior in pure bash using trimming shortest rightside (%) /* pattern and longest leftside (##) */ pattern. More efficient than creating separate sed process for each file
Code:
$ OUTF=${TEMP%/*}/.${TEMP##*/}
$ echo "$OUTF"
/some/path/.file.mood
Bookmarks