sh 文本删除变音符号.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 文本删除变音符号.sh相关的知识,希望对你有一定的参考价值。

#!/bin/bash

srcenc=cp1250
srcenc=iso8859-2
srcenc=cp1252
srcenc=utf8

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

if [ $# -eq 0 ];then
  echo "Usage: $0 directory"
else
  while [ $# -gt 0 ];do
    if [ -d "$1" ];then
      find "$1" -mindepth 1 -maxdepth 1 | grep -v ".svn" | while read name;do
        #echo "INFO: Dir/Filename - $name"
        nname="$(iconv -f "$srcenc" -t "ascii//TRANSLIT" <<< "$name" )"
        nname="$(echo "$nname" | sed -e "s/’//g" )"
        if [ "$name" != "$nname" ];then
          if [ -e "$nname" ];then
            echo "WARNING: Filename already exist - $nname"
            i=0
            oname="$nname"
            while [ -e "$nname" ];do nname="$( printf "%s.%05i" "$oname" $i )";i=$(($i+1));done
          fi
		  ## custom fixes
		  #nname=`echo $nname | sed -e 's/.*/\L&/; s/[a-z]*/\u&/g; s/  /_/g; s/ /_/g'`
		  pname=`echo $nname | sed -e 's/\(.*\/\)\(.*\)/\1/'`
		  #echo $dname
		  if [ x`ls -ld ${name}|sed -e 's/^\(.\).*/\1/'` == "xd" ]; then
			#dir
			fname=`echo $nname | sed -e 's/\(.*\/\)\(.*\)/\2/; s/[a-z]*/\L&/g; s/[a-z]*/\u&/g; s/  //g; s/ //g'`
		  else
			#file
			fname=`echo $nname | sed -e 's/\(.*\/\)\(.*\)\.\(.*\)/\2\.\3/; s/[a-z]*/\L&/g; s/[a-z]*/\u&/g; s/  /_/g; s/ /_/g; s/_-_/-/g; s/\.-/-/g; s/\._/_/g;'`
		  fi
		  #echo $fname
		  nname="${pname}${fname}"
		  #echo $nname
		  # -e 's/.*\/  /_/g; s/.*\/ /_/g'`
          #svn rename "$name" "$nname"
          echo mv -v \"$name\" \"$nname\"
        fi
      done
      find "$1" -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0r "$0" | sed -e "s:[-a-zA-Z0-9_/. \]*.svn ::g"
      #find "$1" -mindepth 1 -maxdepth 1 -type f -print0 | xargs -0r "$0" | sed -e "s:[-a-zA-Z0-9_/. \]*.svn ::g"
      shift
    else
      echo "Directory $1 does not exist"
    fi
  done
fi
#restore $IFS
IFS=$SAVEIF

以上是关于sh 文本删除变音符号.sh的主要内容,如果未能解决你的问题,请参考以下文章

python 删除变音符号去掉文本中字符的附加符号

名称标准化 - 删除变音符号

删除变音符号,某些字母上的某些变音符号除外

用英语等价物替换德语字符(变音符号、重音符号)

MongoDB 匹配部分文本忽略重音符号(变音符号)

javascript JS - 删除变音符号fn