Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert a file_name from upper case to lower case 1

Status
Not open for further replies.

dunk2

Technical User
Jun 10, 2002
14
IE
Hi,

I want to convert a couple of hundred file names in a folder from upper case to lower case.
e.g. /tmp/UPPERCASE1.DATA to /tmp/uppercase2.data
I'm using a Solaris 2.8 platform. Is there a neat awk script that can do this?
 
Doesn't handle characters with "funny" filenames and probably doesn't handle spaces in the filename:

# tolower.sh: convert file names to lower case
# in the current working directory
# Choose either all the files in a directory or
# a command-line list
if [ "$#" -gt 0 ]; then
filelist="$@" # just the files on command line
else
filelist=`ls` # all files
fi
for file in $filelist; do
# Use the grep command to determine if the file
# has an upper case letter
# Determine the destination of the mv command by
# down shifting all the
# letters in the file name. Command substituting an
# echo of the file name to the translate filter, tr,
# performs the downshift
if echo "$file"|grep [A-Z] > /dev/null; then
mv "$file" `echo "$file"|tr "[A-Z]" "[a-z]"`
fi
done
 

I like olded's solution better, but here is an awk solution.

ls -1 *.DATA | nawk '{system ("mv " $0 " " tolower($0))}' CaKiwi
 
Thanks guys, that worked a treat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top