Transforming a filename with 'tr' using RegEx doesn't work

I want to use the tr command to rename something like filename.ext to someName.ext.

To do that I’ve tried

echo "filename.ext" | tr -c ".a-z" "someName"`

to replace the complement (-c) of the filename extension (specified as period, followed by lower-case letters) with the new basename.

However, it does not work – tr isn’t recognizing it as a complement of a period followed by small case alphabets to be replaced by something else.

What am I missing here?

Asked By: Abhishek A Udupa

||

The tr command does not use regex. It uses character ranges and lists and does one for one character replacements or deletions.

For example, tr A-Z a-z would translate uppercase letters to lowercase letters.

If you want to replace by regex, use sed instead of tr.

Answered By: user10489