Search code examples
bashfilewildcardrenaming

Copying The Name Of One File To Another In Bash With Wild Cards


How can I copy the name of *.mkv to poster.jpg in bash using wild cards.

Thanks


Solution

  • If you want to match to files with *.mkv in the name, and for each file named <foo>.mkv, you want to create a foo.jpg, you can use regular expressions with parentheses around the parts of the regular expression you want to match, and then use ${BASH_REMATCH[n]} to access the n'th matched part of the regular expression and reuse it elsewhere. There's an example here: bash regex match string.

    If you're trying to do something completely different from what I just described, it would probably be a good idea to make your question clearer.