Converting filenames to lowercase - Questions
This is a discussion on Converting filenames to lowercase - Questions ; 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. ...
-
Converting filenames to lowercase
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/
-
Re: Converting filenames to lowercase
Mark Hobley wrote:
> 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.
-
Re: Converting filenames to lowercase
Mark Hobley wrote:
> 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:]
-
Re: Converting filenames to lowercase
echo "FiLENAMe" | tr [A-Z] [a-z]
chris dewbery wrote:
>Mark Hobley wrote:
>
>
>>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
-
Re: Converting filenames to lowercase
On 2005-10-31, Mark Hobley wrote:
> 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:
| Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
-
Re: Converting filenames to lowercase
Mark Hobley wrote:
> 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
-
Re: Converting filenames to lowercase
On 2005-10-31, Thobias Vakayil wrote:
[please don't top post; reply moved]
> chris dewbery wrote:
>>Mark Hobley wrote:
>>
>>
>>>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.
> 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:
| Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress