sed删除空白行

sed删除空白行

 

sed删除空白行是通过:

sed '/^$/d'

这里用了正则表达式,^$代表空白行

d是sed的操作符删除

 

    1    [xxx@localhost work]$ cat test.txt | sed '/^$/d'
     2    here you got first line
     3    second line here
     4    aove space line
     5    [xxx@localhost work]$ cat test.txt
     6    here you got first line
     7    second line here
       
     8    aove space line
     9    [xxx@localhost work]$ sed '/^$/d' test.txt
    10    here you got first line
    11    second line here
    12    aove space line
    13    [xxx@localhost work]$ cat test.txt
    14    here you got first line
    15    second line here
       
    16    aove space line
    17    [xxx@localhost work]$ sed '/^$/d' -i test.txt
    18    [xxx@localhost work]$ cat test.txt
    19    here you got first line
    20    second line here
    21    aove space line
    22    [xxx@localhost work]$

 

 

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

Leave a Reply

Your email address will not be published. Required fields are marked *