Remove carriage return in Unix

后端 未结 21 2191
傲寒
傲寒 2020-11-22 03:40

What is the simplest way to remove all the carriage returns \\r from a file in Unix?

21条回答
  •  北海茫月
    2020-11-22 03:55

    I made this shell-script to remove the \r character. It works in solaris and red-hat:

    #!/bin/ksh
    
    LOCALPATH=/Any_PATH
    
    for File in `ls ${LOCALPATH}`
    do
       ARCACT=${LOCALPATH}/${File}
       od -bc ${ARCACT}|sed -n 'p;n'|sed 's/015/012/g'|awk '{$1=""; print $0}'|sed 's/ /\\/g'|awk '{printf $0;}'>${ARCACT}.TMP
       printf "`cat ${ARCACT}.TMP`"|sed '/^$/d'>${ARCACT}
       rm ${ARCACT}.TMP
    done
    
    exit 0
    

提交回复
热议问题