GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Operating System  >  Unix Programming

 Print  |  
Question:  Write a korn shell script for renaming the filenames of the files stored in a folder to lower case.



February 02, 2009 19:26:38 #3
 ENIAC   Member Since: February 2009    Total Comments: 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";
}
}

     

 

Back To Question