Discussion:
Converting filenames to lowercase
(too old to reply)
Mark Hobley
2005-10-31 02:08:04 UTC
Permalink
I am using the Almquist Shell (sh).

How can I convert a batch of mixed case filenames to lowercase ?

In the olden days, we used to ftp localhost, and use the ftp name mangling to
provide the case conversion. (Now that is just plain horrible, but we needed
a two minute solution.) Hey .. samba has an equally horrible solution.

Regards,

Mark.
--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/
Ed Morton
2005-10-31 02:47:46 UTC
Permalink
Post by Mark Hobley
I am using the Almquist Shell (sh).
How can I convert a batch of mixed case filenames to lowercase ?
In the olden days, we used to ftp localhost, and use the ftp name mangling to
provide the case conversion. (Now that is just plain horrible, but we needed
a two minute solution.) Hey .. samba has an equally horrible solution.
Regards,
Mark.
man tr

Ed.
chris dewbery
2005-10-31 03:22:35 UTC
Permalink
Post by Mark Hobley
I am using the Almquist Shell (sh).
How can I convert a batch of mixed case filenames to lowercase ?
In the olden days, we used to ftp localhost, and use the ftp name mangling to
provide the case conversion. (Now that is just plain horrible, but we needed
a two minute solution.) Hey .. samba has an equally horrible solution.
Regards,
Mark.
echo "FiLENAMe" | tr [:upper:] [:lower:]
Thobias Vakayil
2005-10-31 03:40:03 UTC
Permalink
echo "FiLENAMe" | tr [A-Z] [a-z]
Post by chris dewbery
Post by Mark Hobley
I am using the Almquist Shell (sh).
How can I convert a batch of mixed case filenames to lowercase ?
In the olden days, we used to ftp localhost, and use the ftp name mangling to
provide the case conversion. (Now that is just plain horrible, but we needed
a two minute solution.) Hey .. samba has an equally horrible solution.
Regards,
Mark.
echo "FiLENAMe" | tr [:upper:] [:lower:]
--
Thobias Vakayil
Alcatel Development India (ADI)
PH: 2349961/72/86 EXTN :7018
Chris F.A. Johnson
2005-10-31 04:02:04 UTC
Permalink
On 2005-10-31, Thobias Vakayil wrote:

[please don't top post; reply moved]
Post by Thobias Vakayil
Post by chris dewbery
Post by Mark Hobley
I am using the Almquist Shell (sh).
How can I convert a batch of mixed case filenames to lowercase ?
In the olden days, we used to ftp localhost, and use the ftp name mangling to
provide the case conversion. (Now that is just plain horrible, but we needed
a two minute solution.) Hey .. samba has an equally horrible solution.
echo "FiLENAMe" | tr [:upper:] [:lower:]
Older versions of tr do not support character classes.
Post by Thobias Vakayil
echo "FiLENAMe" | tr [A-Z] [a-z]
You need to quote the patterns. See what happens when this is
entered in a directory with a number of one-letter filenames:

$ echo "FiLENAMe" | tr [A-Z] [a-z]
tr: too many arguments
Try `tr --help' for more information

$ echo "FiLENAMe" | tr '[A-Z]' '[a-z]'
filename
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
Chris F.A. Johnson
2005-10-31 03:57:05 UTC
Permalink
Post by Mark Hobley
I am using the Almquist Shell (sh).
How can I convert a batch of mixed case filenames to lowercase ?
Ed suggested tr, but pure shell methods may be faster. These
functions convert uppercase characters to lowercase:

_lwr_str()
{
_LWR_STR=$1
while :
do
case $_LWR_STR in
[A-Z]*) _lwr "$_LWR_STR"
_LWR_STR=$_LWR${_LWR_STR#?}
;;
*[A-Z]*) lwr_left=${_LWR_STR%%[A-Z]*}
lwr_right=${_LWR_STR#"$lwr_left"}
_lwr "$lwr_right"
_LWR_STR=$lwr_left$_LWR${lwr_right#?}
;;
*) break ;;
esac
done
}

_lwr()
{
_LWR=
case $1 in
A*) _LWR=a ;; B*) _LWR=b ;;
C*) _LWR=c ;; D*) _LWR=d ;;
E*) _LWR=e ;; F*) _LWR=f ;;
G*) _LWR=g ;; H*) _LWR=h ;;
I*) _LWR=i ;; J*) _LWR=j ;;
K*) _LWR=k ;; L*) _LWR=l ;;
M*) _LWR=m ;; N*) _LWR=n ;;
O*) _LWR=o ;; P*) _LWR=p ;;
Q*) _LWR=q ;; R*) _LWR=r ;;
S*) _LWR=s ;; T*) _LWR=t ;;
U*) _LWR=u ;; V*) _LWR=v ;;
W*) _LWR=w ;; X*) _LWR=x ;;
Y*) _LWR=y ;; Z*) _LWR=z ;;
*) _LWR=${1%${1#?}} ;;
esac
}


One way to use these functions is:

for file in *[A-Z]*
do
_lwr_str "$file"
mv "$file" "$_LWR_STR"
done
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
John W. Krahn
2005-10-31 04:00:09 UTC
Permalink
Post by Mark Hobley
I am using the Almquist Shell (sh).
How can I convert a batch of mixed case filenames to lowercase ?
mmv '*' '#l1'



John
--
use Perl;
program
fulfillment
Continue reading on narkive:
Loading...