Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(not really) easy

Status
Not open for further replies.

iribach

Technical User
Oct 12, 2002
211
CH
hi all,
is there an EASY and SURE way to translate (stupid)filenames containing spaces, [ ` ^ $ \ ; &quot; ' & * % | > < all-brakets ] + special chars >127 and so on
to standard unix filenames, changing this characters BUT preserving the (unique)name ? exemple:

'\\ab` \234 ab' -> __ab1____x_ab
'\\ab^ \234 ab' -> __ab2____x_ab

sure in c, using opendir(), readdir(), char *xx on filename to check all characters and changing them, then re-readdir() to assure the new name
is unique ... i am looking for an one-liner sh|sed|awk|perl script.
thanks a lot.
ira
PS: we have a lot of users not knowing, they are writing dos-files on a unix server :(
 
Look at man pages for tr
or try this ( untested ! )

for file in * # you decide on the range
do
mv $file `echo $file | tr -c '[A-Z][a-z][0-9]' '[_*]' `
done

HTH
Dickie Bird (:)-)))
 
thanks dickiebird,
tr is a good utility, but what about unique filenames ?
'\\ab` \234 ab' -> __ab1____x_ab
'\\ab^ \234 ab' -> __ab2____x_ab
 
I would try tr twice piped :

for file in a????
do
mv $file `echo $file |tr '\`\^\`\-\_' '12345'| tr -c '[A-Z][a-z][0-9]' '[_*]' `
done

i.e Replace up to 10 punctuations with 0 to 9 then tr the complement of that.
NB Still untested

HTH Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top