LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Convert Extension from Uppercase to Lowercase (https://www.linuxquestions.org/questions/linux-newbie-8/convert-extension-from-uppercase-to-lowercase-4175660870/)

zetrotrack000 09-13-2019 02:26 PM

Convert Extension from Uppercase to Lowercase
 
Hi
I have several fonts in ~/.fonts directory. Some of these fonts' extension are in uppercase and some are in lowercase, like:
Code:

font1.TTF  font2.Ttf  Font3.tTF
font4.ttf  FONT5.ttF...

and I want to convert all these extensions to lower case, like:
Code:

font1.ttf  font2.ttf  Font3.ttf
font4.ttf  FONT5.ttf...

That is, I don't want to convert the fonts' name, but only want to convert its extension from uppercase to lowercase.
Kindly guide me that how can I do it with single command?
Thanks

BW-userx 09-13-2019 02:48 PM

a little bash script or one liner, depending on how you write it up.

Code:


#!/usr/bin/env bash

while read f
do
        path=${f%/*}
        filen=$(basename $f)
        ext=${filen##*.}
        file=${filen%.*}
        echo "mv -v $f $path/$file.${ext,,}"
       
done <<<$( find  /usr/local/share/fonts/TTF -type f -iname "*.ttf" )

yes there are other ways to do this...

Firerat 09-13-2019 02:49 PM

Code:

for i in ~/.fonts/*;do
  if [[ ${i} != ${i,,[${i##*.}]} ]]
  then
      echo mv -v \"${i}\" \"${i,,[${i##*.}]}\"
  fi
done

if you are happy that the mobes are fine, pipe it to sh

or drop the echo ( and drop the \s )

teckk 09-13-2019 02:49 PM

Code:

fonts=(font1.TTF font2.Ttf Font3.tTF font4.ttf FONT5.ttF)

for i in "${fonts[@]}"; do echo "${i,,}"; done
font1.ttf
font2.ttf
font3.ttf
font4.ttf
font5.ttf

for i in "${fonts[@]}"; do echo ""${i%.*}".ttf"; done
font1.ttf
font2.ttf
Font3.ttf
font4.ttf
FONT5.ttf


ondoho 09-13-2019 03:00 PM

^ all these will probably work.
Question is, why do you (think you) need this?

Firerat 09-13-2019 03:05 PM

oh, wait you wanted a single command ;)

Code:

EXT2ext() {
for i in "${@}";do
  if [[ ${i} != ${i,,[${i##*.}]} ]]
  then
      mv -v "${i}" "${i,,[${i##*.}]}"
  fi
done
}

stick that in ~/.bash_extras
Code:

. ~/.bash_extras

EXT2ext ~/.fonts/*

and if you have . ~/.bash_extras in ~/.bashrc you will have it every bash session

note the leading . ( short for source )

zetrotrack000 09-14-2019 07:27 AM

Thanks everyone. Each of these was working, however, I used following:
Code:

#!/usr/bin/env bash

while read f
do
        path=${f%/*}
        filen=$(basename $f)
        ext=${filen##*.}
        file=${filen%.*}
        echo "mv -v $f $path/$file.${ext,,}"
       
done <<<$( find  /usr/local/share/fonts/TTF -type f -iname "*.ttf" )

Thanks again :-)

zetrotrack000 09-14-2019 07:27 AM

After this change, do I need to regenerate fonts cache?

Firerat 09-14-2019 07:32 AM

well the filenames will be different.
so probably

It could be automagic

zetrotrack000 09-14-2019 01:24 PM

Quote:

Originally Posted by Firerat (Post 6036688)
well the filenames will be different.
so probably

It could be automagic

Thanks


All times are GMT -5. The time now is 05:13 AM.