您的位置:首页 > 运维架构 > Shell

实现dos2linux功能-shell脚本篇

2012-11-12 19:58 591 查看
#! /bin/bash
  # Programe:
  #       To change the the file with end of \r\n, into linux style with end of \n
  # History:
  #       2012/11/12      ZL      FirstRelease
 
  # function:
  #       To ergodic the diretory
  function ergodic(){
          for file in ` ls $1 `
          do
                  if [ -d $1"/"$file ]
                  then
                          ergodic $1"/"$file
                  else
                          file="$1"/"$file"
                          func $file;
                          echo "$file";
                          read -p "dd" X
                  fi
          done
 }
 
 # Function:
 #       To make the file with end of \r\n into \n
 function func () {
         tmp=".tmp";
         echo  > .tmp
         sed 's/\r$//g' $1 >> .tmp  # \r\n ===> \n
         cat $tmp > $1
         sed -i '1d' $1
 }
 
 # Function:
 #       To start the main
 read -p "Please input the file/directory(U want change the dos style to unixone):" INIT_PATH;
 INIT_PATH=`echo $INIT_PATH | sed 's/\/$//g'`; #"/home/" ===> "/home"
 ergodic $INIT_PATH



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: