regex - script to rename filenames containing backslash -
i trying write shell script rename result of 7-zipped folders. resulting filenames contains backslash \ in filename. wrote simple :
#! /bin/sh n in * oldname=$n newname=`echo "$n" | tr -s '\' "#" | tr -s " " "_"` echo $newname mv "$oldname" "$newname" done the problem have \01 interpreted echo, , files : fld\01.02.2015 thefile.pdf
thus, echo "fld\01.02.2015 thefile.pdf" returns fld?.2015.
i have tried various replacement solutions, s/\/#/g, sed, tr. tried use printf instead have search on net without finding valid solution.
nothing works. need solution work on unix , mac os x.
the "working" solution
ls > liste.txt sed -e 's/\\/,/g' liste.txt and parse liste.txt, escape backslash, generate rename.sh , execute it. seems dirty me.
does has suggestion ?
instead of using echo rename filename can (in bash):
newname="${oldname//\\/}" example:
oldname="fld\01.02.2015 thefile.pdf" newname="${oldname//\\/}" echo "$newname" it print out:
fld01.02.2015 thefile.pdf note: need change shebang #!/bin/bash use bash parameter expansion.
Comments
Post a Comment