PDA

View Full Version : How to remove double and single quotes from filenames



mattywix
14th November 2008, 12:21 PM
Hi
How can I remove double and single quotes and spaces from filenames?
I need to drive this from the command line using a

for i in folder/*.flv; do
...secret guru conversion...
done

A single filename could be for example:
My hippo's "bottamus" really stinks bad.flv
This should end up as:
My_hippos_bottamus_really_stinks_bad.flv

No gui answers please!

leigh123linux
14th November 2008, 12:24 PM
Thread re-titled .

mattywix
14th November 2008, 01:00 PM
Never mind, a bit of perserverance and I fiddled it into working.
for i in folder/*flv; do mv -v "$i" $(echo $i | sed "s/[ \"\']/_/g"); done

ValHolla
14th November 2008, 07:45 PM
a nifty shortcut would be
perl -pi -e "s/\'|\"//g" folder/*.flv
you can do lump this with a find command also...

perl -pi -e "s/\'|\"//g" $(find dir -name \*.flv -print)

ValHolla
14th November 2008, 07:51 PM
woops, you are talking renaming, I miss read the first post.....:p

well, the perl code is quite handy to have on hand regardless ;)

sideways
14th November 2008, 10:13 PM
can also just cd to folder and repeat the following commands,


rename \' _ *flv
rename \" _ *flv