删除DOS结尾符

DOS结尾符:CRLF Carriage-Return Line-Feed 

# 检查文件是否含有CRLF
1. file dosfile
   返回CRLF

2. cat -a dosfile
   返回^M  
        
# 删除CRLF
1. vim      
    :set fileformat=unix  # :set ff=unix
    :wq  
    
    :% s/^M//gc  # Linux: Ctrl+V+M Enter, AIX: Ctrl+V Ctrl+^ Enter
    :wq
    
2. dos2uninx dosfile    
    
3. col -bx dosfile

4. cat & sed 
sed -e 's/^M//' dosfile
cat -v dosfile | sed 's/\^M$//g'
cat -v dosfile | sed 's/.M//g'
5. tr                 
tr -s "\r\n" "\n" dosfile
tr -d "\r" dosfile 
tr -d "\015" dosfile

6. awk
awk '{sub(/\r$/,"");print}' dosfile
7. perl
perl -pe '~s/\r//g' dosfile

 

你可能感兴趣的:(dos)