美文网首页
Linux sed命令使用,全文替换特殊字符

Linux sed命令使用,全文替换特殊字符

作者: 南风nanfeng | 来源:发表于2019-08-13 17:54 被阅读0次

    遍历、替换

    #!/bin/sh
    filePath=/data2/r_test/20190807/20190807/*
    for file in $filePath
    do
    if [ -d "$file" ]
    then
      echo "$file is directory"
    elif [ -f "$file" ]
    then
    echo "file is $file ..."
    sed -i 's/\r\n//g' $file
    sed -i 's/\r//g' $file
    sed -i 's/\n\r//g' $file
    sed -i 's/\n//g' $file
    sed -i 's/}{/}\n{/g' $file
    fi
    done
    

    解压、遍历、替换

    #!/bin/sh
    zipArray=(20190808_04.zip 20190808_05.zip 20190808_06.zip 20190808_07.zip 20190808_08.zip 20190808_09.zip 20190808_10.zip 20190808_11.zip 20190808_12.zip 20190808_13.zip 20190808_14.zip 20190808_15.zip 20190808_16.zip)
    index=0
    for i in ${zipArray[@]}
    do
      fileName=${i%%.*}
      dateDir=${i%%_*}
      hh=${fileName##*_}
      echo "the ${index}'s value is : ${i%%.*}, date is : ${i%%_*}, hh is : ${fileName##*_}"
      rm -rf ./${fileName}/${dateDir}
      let index++
      #unzip -o $i -d ./$fileName
      #txtFile=./${fileName}/${dateDir}/king_war_score_log${hh}.txt
      #sed -i 's/\r\n//g' $txtFile
      #sed -i 's/\r//g' $txtFile
      #sed -i 's/\n\r//g' $txtFile
      #sed -i 's/\n//g' $txtFile
      #sed -i 's/}{/}\n{/g' $txtFile
    done
    

    相关文章

      网友评论

          本文标题:Linux sed命令使用,全文替换特殊字符

          本文链接:https://www.haomeiwen.com/subject/qcwbjctx.html