1)
To those who haven't noticed, this is a 3 year old thread that has been reopened. It's usually a good idea to not post to old threads unless you specifically have something important to add to the previous discussion. New questions should be made in new threads, perhaps with a referral to the old one if relevant.
2)
Please use
[code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
3)
When you post, please give us all the relevant details about what you are trying to do. What platform are you using, where are you getting your data, what format is it in, etc.
For example, the old discussion focused on the the occurrence of '
\r' in the string. You'll generally only see that as the result of dos-style line endings when operating on files written in Windows. So I suspect the filenames were taken from a windows-created text file, rather than directly. A simple conversion of the file first, or stripping off the last character, would fix that.
4)
For
pampano, there are many string manipulations that can be done with shell built-in commands, so probably you won't need to call on sed or another external command.
parameter substitution
string manipulation
And again, you need to define your requirements clearly. Do you just need to lowercase the whole variable? Or ensure that only the extension is lowercase? To use recent bash for that:
Code:
filename='Foobar.TXT'
echo "${filename,,}" #lowercases the entire filename
ext=${filename##*.} #grabs the extension from the filename
echo "${filename%.*}.${ext,,}" #echos the filename without extension,
#plus lowercased extension.
As for changing the extension, All you need to know has been presented already:
Code:
filename='kingsandqueens.dat'
echo "${filename%.*}.backup"