[Gllug] Making filenames 'FAT-safe' in bash

Dylan dylan at dylan.me.uk
Tue Nov 30 14:48:58 UTC 2010


On Tuesday 30 Nov 2010, - Tethys wrote:
> On Tue, Nov 30, 2010 at 12:30 PM, Dylan <dylan at dylan.me.uk> wrote:
> > I have a bash script which takes a list of files and copies them to a 
usb
> > stick, partially re-creating the original directory structure as it 
goes.
> > This all functions as expected until it reaches a file with non-FAT
> > compatible characters. So, how do I remove these characters? I need to
> > handle filenames with ' and " in them as well as ?, !, (, ), [, ], & ...
> 
> I do it with tr and sed, for creating mp3 filenames that the car
> stereo doesn't barf on:
> 
> safename=$(echo "$name" | tr '[:upper:]' '[:lower:]' | \
> 		sed 's/ *- */_/g;s/  */_/g' | \
> 		sed -f /local/share/deunicode.sed | \
> 		sed 's/[^0-9a-z_]//g;s/__*/_/g')
> 
> deunicode.sed contains:
SNIP
> 
> It's not perfect, but it's good enough for what I need (and probably
> for what you need).

That's great, thanks - but it also removes the / between directory names and 
the final . before the filoe extension ...

Dx

> 
> Tet


-- 
" '... but there is so much else behind what I say. It makes itself known to 
me so slowly, so incompletely! ...' "
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list