溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

sed 處理文件中 dos CR/LF

發(fā)布時(shí)間:2020-07-10 00:55:44 來源:網(wǎng)絡(luò) 閱讀:790 作者:aaronzzq 欄目:系統(tǒng)運(yùn)維

 dos控制字符^M替換掉;

  # IN unix ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format)
     sed 's/^M$//'              # in bash/tcsh, press Ctrl-V then Ctrl-M
     sed 's/.$//'               # assumes that all lines end with CR/LF 
     sed 's/\x0D$//'            # gsed 3.02.80, but top script is easier 
  
  # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format 
     sed "s/$/`echo -e 
\\\r`/"  # command line under ksh 
     sed 's/$'"/`echo 
\\\r`/"   # command line under bash 
     sed "s/$/`echo 
\\\r`/"     # command line under zsh 
     sed 's/$/\r/'              # gsed 3.02.80

  # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format 
     sed "s/$//"                # method 1 
     sed -n p                   # method 2

  # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format 
  # Cannot be done with DOS versions of sed. Use "tr" instead. 
     tr -d \r outfile  # GNU tr version 1.22 or higher


Example:
刪除文件中的所有空行和由空格組成的行;
$cat ifile|sed '/^$/d'|sed '/^[[:space:]]*$/d'    # method 1
$cat ifile|sed -e '/^$/d' -e '/^[[:space:]]*$/d'  # method 2

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI