我想将一个linux文件重命名为在Windows中合法的文件名。 它不应该超过允许的时间,不应该有窗口中不允许的字符。 有时我把文件的标题复制到一个文件名,并且有特殊的字符如–
, ®
或?
在从pdf复制和粘贴标题时,有时会在某些行的末尾出现某些字符。 在使用sed -n'l'时可以看到它们:
echo 'Estrogen receptor agonists and estrogen attenuate TNF-α induced α apoptosis in VSC4.1 motoneurons.pdf' | sed -n 'l' Estrogen receptor agonists and estrogen attenuate TNF-\316\261 induce\ d$ \316\261$ apoptosis in VSC4.1 motoneurons.pdf$
要么
echo 'A synthetic review of the five molecular Sorlie's subtypes in breast cancer' | sed -n 'l' A synthetic review of the \357\254\201ve molecular Sorlie\342\200\231\ s subtypes in$ breast cancer$
我已经开始了一个脚本,但它不是优雅和不完整的。 有人做过这样的事情,或者有一个快捷的方法来做到这一点?
fn2win="$1" testFn=$(echo "$fn2win" | sed -n 'l') #SPEC_CHAR="ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞàáâãäåçèéêëìíîïðñòóôõöøùúûüýþÿ" #NORM_CHAR="AAAAAACEEEEIIIIDNOOOOOOUUUUYPaaaaaaceeeeiiiionoooooouuuuyby" #SPEC_LOW_CHAR="aàáâãäåāăąbḃcćçčĉċdḑďḋđeèéěêëēĕęėfḟƒgǵģǧĝğġǥhĥħiìíîĩïīĭįıjĵkḱķǩlĺļľłmṁnńņňñoòóôõöōŏøpṗqrŕŗřsśşšŝṡſtţťṫŧuùúûũüůūŭųvwẁẃŵẅxyỳýŷÿzźžż" #NORM_LOW_CHAR="aaaaaaaaaabbccccccdddddeeeeeeeeeefffgggggggghhhiiiiiiiiiijjkkkklllllmmnnnnnoooooooooppqrrrrssssssstttttuuuuuuuuuuvwwwwwxyyyyyzzzz" #SPEC_CAP_CHAR="AÀÁÂÃÄÅĀĂĄBḂCĆÇČĈĊDḐĎḊĐEÈÉĚÊËĒĔĘĖFḞGǴĢǦĜĞĠǤHĤĦIÌÍÎĨÏĪĬĮİJĴKḰĶǨĸLĹĻĽŁMṀNŃŅŇÑOÒÓÔÕÖŌŎØPṖQRŔŖŘSŚŞŠŜṠTŢŤṪŦUÙÚÛŨÜŮŪŬŲVWẀẂŴẄXYỲÝŶŸZŹŽŻ" #SPEC_CAP_CHAR="AAAAAAAAAABBCCCCCCDDDDDEEEEEEEEEEFFGGGGGGGGHHHIIIIIIIIIIJJKKKKKLLLLLMMNNNNNOOOOOOOOOPPQRRRRSSSSSSTTTTTUUUUUUUUUUVWWWWWXYYYYYZZZZ" #sed -e "y/'$SPEC_CHAR'/'$NORM_CHAR'/" if [ "$fn2win" != "$testFn" ]; then newLinFn=$(echo "$fn2win" | fromdos | tr "\n" " " |\ sed -e " s/[?()\[\]=+<>:;©®”,*|]/_/g s/"$'\t'"/ /g s/–/-/g s/'/'/g s/α/alpha/g s/β/beta/g s/µ/micro/g s/Æ/AE/g s/Ǽ/AE/g s/æ/ae/g s/ǽ/ae/g s/DZ/DZ/g s/DŽ/DZ/g s/Dž/Dz/g s/Dz/Dz/g s/dz/dz/g s/dž/dz/g s/ff/ff/g s/fi/fi/g s/fl/fl/g s/ffi/ffi/g s/ffl/ffl/g s/ſt/ft/g s/IJ/IJ/g s/ij/ij/g s/LJ/LJ/g s/Lj/Lj/g s/lj/lj/g s/NJ/NJ/g s/Nj/Nj/g s/nj/nj/g s/Œ/OE/g s/œ/oe/g s/ß/SZ/g s/\"/_/g s/[[:cntrl:]]/_/g s/\ $//g " |\ fold -s -w 251 | head -1 | sed 's/\ $/.pdf/') if [ "$fn2win" != "$newLinFn" ]; then mv "$fn2win" "$newLinFn" fi fi winFn=$(echo "z:"$newLinFn | sed 's/\//\\/g' )
这看起来应该这样做: http : //pwet.fr/man/linux/commandes/konwert