LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-13-2019, 02:26 PM   #1
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 387

Rep: Reputation: Disabled
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
 
Old 09-13-2019, 02:48 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,133

Rep: Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925
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...

Last edited by BW-userx; 09-13-2019 at 02:51 PM.
 
Old 09-13-2019, 02:49 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,320

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
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 )
 
Old 09-13-2019, 02:49 PM   #4
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 2,331

Rep: Reputation: 510Reputation: 510Reputation: 510Reputation: 510Reputation: 510Reputation: 510
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
 
1 members found this post helpful.
Old 09-13-2019, 03:00 PM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,463
Blog Entries: 9

Rep: Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372
^ all these will probably work.
Question is, why do you (think you) need this?
 
Old 09-13-2019, 03:05 PM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,320

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
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 )
 
Old 09-14-2019, 07:27 AM   #7
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 387

Original Poster
Rep: Reputation: Disabled
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 :-)
 
Old 09-14-2019, 07:27 AM   #8
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 387

Original Poster
Rep: Reputation: Disabled
After this change, do I need to regenerate fonts cache?
 
Old 09-14-2019, 07:32 AM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,320

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
well the filenames will be different.
so probably

It could be automagic
 
Old 09-14-2019, 01:24 PM   #10
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 387

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
well the filenames will be different.
so probably

It could be automagic
Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Joining line ending with lowercase and starting with lowercase, or uppercase hurd Linux - Newbie 11 05-01-2016 01:29 PM
how to convert lowercase to uppercase to all letters within a directory? kee23 Linux - Newbie 5 10-11-2015 10:29 AM
UPPERCASE to lowercase command? pk21 Linux - General 4 06-12-2007 10:26 AM
Converting Uppercase to Lowercase AMMullan Linux - Software 6 10-18-2005 07:32 PM
Converting lowercase to uppercase noodle123 Programming 1 05-17-2002 02:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration