网站建设资讯

NEWS

网站建设资讯

sed处理文件中dosCR/LF

 将dos控制字符^M替换掉;

我们提供的服务有:成都网站设计、成都网站制作、微信公众号开发、网站优化、网站认证、北戴河ssl等。为千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的北戴河网站制作公司

  # 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


当前题目:sed处理文件中dosCR/LF
标题链接:http://njwzjz.com/article/iesgjs.html