GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Unix Programming
Go To First  |  Previous Question  |  Next Question 
 Unix Programming  |  Question 36 of 43    Print  
Write a korn shell script for renaming the filenames of the files stored in a folder to lower case.

  
Total Answers and Comments: 4 Last Update: May 27, 2009     Asked by: renjiraj 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 29, 2007 06:47:25   #1  
amitmittal Member Since: November 2007   Contribution: 1    

RE: Write a korn shell script for renaming the filenames of the files stored in a folder to lower case.
folder $1

list_of_files `ls $folder`

for file in $list_of_files;
do
mv $file `echo $file | tr [:upper:] [:lower:]`
done;

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
February 18, 2009 21:19:56   #2  
ENIAC Member Since: February 2009   Contribution: 2    

RE: Write a korn shell script for renaming the filenames of the files stored in a folder to lower case.
It picks up directory names inside the folder and renames them.
I'll be building a proper KSH version soon enough. Stay tuned.

 
Is this answer useful? Yes | No
February 23, 2009 19:26:38   #3  
ENIAC Member Since: February 2009   Contribution: 2    

Here's the GAWK version - simplified

#!/bin/gawk -f
#
# LowerFiles.gawk
#
# Using GAWK we can strip off the file name from the full path
# and rename it only when necessary (skip files that are already lowercase.)
# Usage example
#
# find . -type f -print | ./LowerFiles.gawk | ksh
#
# If you skip the 'ksh' portion you can get a dry run
# of the command output or redirect
#

BEGIN {
FS "/";
}
{
if ( $NF ~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/ ) {
printf "mv "$0" ";
for (i 1; i<NF; i++) {
printf $i"/";
}

printf tolower($NF);
printf "n";
}
}


 
Is this answer useful? Yes | No
May 27, 2009 07:41:55   #4  
Rohit_Ash Member Since: May 2009   Contribution: 6    

RE: Write a korn shell script for renaming the filenames of the files stored in a folder to lower case.
Tested script.

#! /usr/bin/ksh
echo "start"
for name in `ls -1`
do
echo "name $name"
name1 `echo $name | tr [A-Z] [a-z]`;
echo "name1 $name1"
mv $name $name1;
if [ -z $name ]
then
exit;
fi
done

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape