Changing cases of multiple files in different folders


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Changing cases of multiple files in different folders
# 1  
Old 11-02-2014
Changing cases of multiple files in different folders

I am a TA for a computer science course and we have a program that flags code that appears to the same as other code that is supplied. In order for the program to check all of the student's programs, the programs all need to be named exactly the same. However, students don't like to follow directions in naming programs.
For example, our students should be naming exam files "exam.f95"
but they sometimes name them "Exam.f95" or "EXAM.f95".
I need to rename all their files to match the correct format, but the files are all in different directories.
I am writing a .sh script to rename the files and run the program. In my script

Code:
find $download_dir -iname "$filename" | tr '[:upper:]' '[:lower:]'

displays the files with the correct name, but does not actually save them as the correct name. how do I go about actually saving the files with the correct name?
# 2  
Old 11-02-2014
This will do it:
Code:
find $download_dir -iname "$filename" | perl -lne 'rename $_, lc $_'

Run this one first and see if that is what you want:
Code:
find $download_dir -iname "$filename" | perl -lne 'print "$_ ", lc $_'

# 3  
Old 11-02-2014
it prints out what I want it to change, but for some reason the 'rename' doesn't seem to work
# 4  
Old 11-02-2014
Quote:
Originally Posted by bpmawhin
it prints out what I want it to change, but for some reason the 'rename' doesn't seem to work
I am sorry, I am not in front of you system to know why it appears not to work for you.
However, if this, you say that works:
Code:
find $download_dir -iname "$filename" | perl -lne 'print "$_ ", lc $_'

Let's leverage this solution by running:
Code:
find $download_dir -iname "$filename" | perl -lne 'print "mv -v $_ ", lc $_' | sh

or if you have a version of bash 4.x
Code:
for f in $(find $download_dir -iname "$filename"); do mv -v $f ${f,,}; done

try first as:
Code:
for f in $(find $download_dir -iname "$filename"); do echo "$f" ${f,,}; done


Last edited by Aia; 11-02-2014 at 08:29 PM.. Reason: changed from upper to lower
This User Gave Thanks to Aia For This Post:
# 5  
Old 11-02-2014
Network

Do you have the rename command on you system? If yes, you could try this:
Code:
find $download_dir -iname "$filename" -exec rename -v 'y/A-Z/a-z/' {} +

# 6  
Old 11-02-2014
the only problem with that is that it also changes my folder names to lower case, which makes it a pathname that doesn't exist, I can change the folder name to be lowercase If there is no other option, but is there a way around that?
I used
Code:
find $download_dir -iname "$filename" | perl -lne 'print "mv -v $_ ", lc $_' | sh


Last edited by bpmawhin; 11-02-2014 at 09:14 PM..
# 7  
Old 11-02-2014
Quote:
Originally Posted by bpmawhin
the only problem with that is that it also changes my folder names to lower case
Same applies to your own approach with tr Smilie

Try this one:
Code:
find $download_dir -iname "$filename" | while read path
do
 fldr=${path%/*}
 oldfile=${path##*/}
 newfile=$(echo "$oldfile" | tr '[:upper:]' '[:lower:]')
 mv -v "$path" "$fldr/$newfile"
done

This User Gave Thanks to junior-helper For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute multiple files in multiple folders and also output on same folder

How to execute multiple files in multiple folders and also output to be generated in the same folder? Hello Team, I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
Discussion started by: pushpabuzz
1 Replies

2. UNIX for Dummies Questions & Answers

Unzipping a file which has multiple folders and each folder has the files with same name in it

Hi, I have a zipped file a.zip. This has got multiple folders in it say x and y. x contains a.txt and y contains a.txt. Is it possible to unzip this file and have the 2 files extracted and rename them to unique names. Thanks in advance. (1 Reply)
Discussion started by: arunkesi
1 Replies

3. Shell Programming and Scripting

Script to move files in multiple folders

Hello all, I would appreciate any help to write a script. I have folder A which contains over 30 thousands xml files, I would like create multiple folders and move those files (500 in each folders). Thank you (1 Reply)
Discussion started by: mmsiddig
1 Replies

4. Shell Programming and Scripting

Shell Script to delete files within a particular time frame under multiple sub folders

Greetings! I'm looking for starting information for a shell script. Here's my scenario: I have multiple folders(100) for example: /www/test/applications/app1/logs /www/test/applications/app2/logs Within these folders there are log files files that need to be deleted after a month. ... (3 Replies)
Discussion started by: whysolucky
3 Replies

5. Shell Programming and Scripting

Find files of type within folder copy multiple results to different folders

Ok question number two: I'd like to search a directory for multiple file types (rar, txt, deb) and depending on what's found, copy those files to folders named Rar, TextFiles, and Debs. I'm looking for speed here so the faster the script the better. I want it to be a function that I pass 1 argument... (4 Replies)
Discussion started by: DC Slick
4 Replies

6. UNIX for Dummies Questions & Answers

Rename files to indexnumber in multiple folders

I have multiple subfolders with multiple jpg I want the group of files in each subfolder renamed to their index number (3 digits) in the folder, so: folder/a.jpg = folder/001.jpg folder/b.jpg = folder/002.jpg folder/c.jpg = folder/003.jpg folder2/1.jpg = folder2/001.jpg folder2/2.jpg =... (2 Replies)
Discussion started by: cmanniche
2 Replies

7. UNIX for Dummies Questions & Answers

mv folders/files without changing modified date?

Hi all, I'm using Red Hat Linux and want to move some folders and files around but not change the modified date. Is this possible? I know cp has a -p flag which seems to do what I want, but this is a large volume of data so copying and deleting would not be feasible. (13 Replies)
Discussion started by: Annorax
13 Replies

8. UNIX for Dummies Questions & Answers

changing extensions for multiple files at once

I copied some files to another folder, and I want to change them from .doc extensions to .txt extensions. I tried using the cp and mv commands, but it didn't work. Is it possible to change file extensions with these commands, and if so how do I do it? I tried using the * wildcard (say cp *.doc... (1 Reply)
Discussion started by: Straitsfan
1 Replies

9. Shell Programming and Scripting

moving multiple folders/files in subversion using bash script

Hi, I'm new here an dlearning a lot from this forum. i didnt find any solution for this in the forum. I have already checked in folders in subversion named HTT01,... HTT21.. and have files in each folder like below: HTT01/HTT01_00000.hex HTT01/HTT01_00000_fb_result.hex... (2 Replies)
Discussion started by: ravishan21
2 Replies

10. Shell Programming and Scripting

Find and replace files in multiple folders

Hi there, I would like to write a script to automate the copy and renaming of files in multiple dir. I have a generic file named s253e.prb and would like to copy this to multiple dir and rename it. Example: Dir is AL-M1 and the prb file name is AL-M1.prb. I would like to be able to... (6 Replies)
Discussion started by: lodey
6 Replies
Login or Register to Ask a Question