I've been googling for the following for the past few weeks several times, but haven't yet come across something that I could easily grasp. Can someone point me in the right direction please?
I'm trying to replace a character in file names, i.e. the character is a period, and I want to replace it with nothing. So, if a file name is file.name, I want to be able to execute a command from the shell that will change it to filename. And if this can be scripted so that whenever the script is executed, it'll take out the periods in file names in whatever directory is specified, even better.
Please point me towards whatever resources that will help me figure this out.
Can you explain the different components of the script? I'm trying to make sense of it (interpreting the script's contents to English) but I'm having trouble understanding it. Also, what are the differences of the code section from the script section?
Try this code. This will get the directory name as the parameter and rename all the filenames with "." in it. I hope the script will be easy for you to understand.
#!/bin/ksh
#Rename the filenames with . in it
if [[ $# != 1 ]]
then
print "Full Directory path is required"
exit 1
fi
for i in `ls $1`
do
newfilename=`print $i | sed 's/\.//g'`
mv $1/$i $1/$newfilename
done
Thanks! I copied and pasted the contents of the script and tested it out with several d*o*t* files I touched, and had fun with it. Thanks!
I do have several questions though ...
1) Can the shell that's used be replaced as sh? I am not sure if the server that has the Unix operating system on has the ksh, although I figure it should. If it can be replaced, will any of the contents have to be modified?
2) Although I have questions about lines 3, 6 - 8, and 10 - 11, 1 being the #!/.../ line, (that's like 99.% of the script's contents ... ) can you clarify your statement "This will get the directory name as the parameter and rename all the filenames with "." in it."? Does it mean that the directory specified will be the criteria in which the script executes its magic on?
I will be manning commands like fi and sed among others that is included in the script to be able to interpret it to English so I can understand it (that seems to be the only way I can comprehend the Unix commands). Whatever summaries you can provide though would help expediate this process though! Just kidding, of course, kind of.