Kachi S.

asked • 06/19/15

developing a shell script that will search for files within a directory whose name contains a space. Your script should replace all spaces in a filename with _

Begin by developing a shell script that will search for files within a directory whose name contains a space. Your script should replace all spaces in a filename with an underscore.

Here is some pseudocode to help you solve this:

loop through all the files in the directory
grep for space in the filename
capture results of grep operation ($?)
Do an if test to see if it did have a space
If it did, echo the filname out and use sed to replace spaces with underscores.
Use mv command to rename file
Maybe echo out a nice message to the user
End if, end loop

2 Answers By Expert Tutors

By:

Peter D. answered • 06/20/15

Tutor
4.9 (112)

PhysicsPhD/MathBS -- 25 years of professional experience with Unix

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.