name with spazce

I need a script that rename each file in a file system ending with a dot
with the same name without the dot.
The files contains spaces.
anacletoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

seredaCommented:
make the following script:
-- file: rmdot.sh
# removes dot
FILENAME=$1
mv $FILENAME `echo $FILENAME | awk '{printf ("%s", substr ($0, 0, length ($0) - 1));}'`
-- end of file

Then run

find / -name "*." -exec $PATH_TO_RMDOT/rmdot.sh '{}' \;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
seredaCommented:
Of course, substitute $PATH_TO_RMDOT with a real path ;)
0
anacletoAuthor Commented:
I'm sorry but this script doesn't work.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

seredaCommented:
Okay, let's see - what is the error?
(What does it output?)

I tested it on my platform - it was ok.
0
anacletoAuthor Commented:
I'm using ksh on aix 4.3.

Usage: mv [-i | -f]  [--] src target
   or: mv [-i | -f]  [--] src1 ... srcN directory

I think that the problem is with
mv $FILENAME `echo $FILENAME | awk '{printf ("%s", substr ($0, 0, length ($0) - 1));}'`
where filename is a name with spaces....
Have you tried with name with blank inside?
0
seredaCommented:
Oh my - i guess you're right.
I thought of blanks in one case and forgot the other.
So, you need to change that line to the following:

mv "$FILENAME" "`echo \"$FILENAME\" | awk '{printf (\"%s\", substr ($0, 0, length ($0) - 1));}'`"

I hope this will help.
Please comment if there are other errors.

PS: if you want to rename only FILES (as said in the first message), then you need to issue more specific find:

find / -name "*." -type f -exec $PATH_TO_RMDOT/rmdot.sh '{}' \;

That will leave directories and links and devices as they are.


0
anacletoAuthor Commented:
Now It is working,and as a workaround I could accept it.
But I have asked ascript to install in my environment...

Could you help me?
ps:we are very close..
0
seredaCommented:
Eeeh, i don't quite catch what you really need. If you need a script that performs those actions, just put 'find' command with parameters shown above into another script file and there you have it.

Yes, you will have two scripts actually, but does it matter?

Please clear up with this and i think i can help you.

0
anacletoAuthor Commented:
There are two point in my request.
1) I prefer to have only one script for doing jobs.It's easier to mantain e remember what things are for.
2) It's a scholastic question regarding filenames that contains spaces.

It was my request "I need a script that rename each file in a file ..."

...



0
seredaCommented:
Okay, i take it that you need only one script. Unfortunately, it's not obvious how to make "find" run several commands with {} argument, so i propose a workaround here - it is ONE script:

-- start of rmdot.sh
# This script will remove all dots
# from the end of files by issuing
# find command ans executing itself
# for each filename

# Important: Run this script without parameters

# Put here path to this script
PATH_TO_SELF=/

FILENAME=$1

if [ "x$FILENAME" = "x" ]; then
# this is main call without parameters

  find / -name "*." -type f -exec  $PATH_TO_SELF/rmdot.sh '{}' \;

else
# this is call from find - remove dot

  mv "$FILENAME" "`echo \"$FILENAME\" | awk '{printf (\"%s\", substr ($0, 0, length ($0) - 1));}'`"

fi

# That's it.
-- end of file
0
seredaCommented:
Oh my, i am really stupid ;)
You may remove $PATH_TO_SELF here - just change 'find' command to

find / -name "*." -type f -exec  $0 '{}' \;

0
anacletoAuthor Commented:
Good suggestions. But It's not exactly what I'm lookin for.(consider the second point..)
I can grade this wiht good. if you want more. You can go on...

It's up to you.
0
seredaCommented:
> 2) It's a scholastic question regarding filenames that contains spaces.

So, what's the question?
You can manipulate filenames that contain spaces, but you need to make your shell understand that this is really one parameter and not two-or-more.
For example,
    mv my pretty file my pretty dir/
will run mv command with $1=my $2=pretty etc., and
    mv "my pretty file" "my pretty dir"/
will run mv command with $1=my pretty file and $2=my pretty dir.

I think that's pretty plain, and if you need more explanation, please ask more concrete questions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.