• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • sed: delete all blank lines from a text file

    Here our requirement is to remove all the blank lines from a file.







    Our sample file
    [root@golinuxhub ~]# cat /tmp/file
    This is line one

    This is line two
    This is line three

    This is line four

    [root@golinuxhub ~]#

    Use the below command to remove all the blank lines from a text file
    [root@golinuxhub ~]# sed -e '/^$/d' /tmp/file
    This is line one
    This is line two
    This is line three
    This is line four
    [root@golinuxhub ~]#

    Here the regular expressions used are
    ^ - means starting with
    $ - means ending with

    Since we did not provided any other other character between our regular expressions, this is a notation to consider it as blank line.

    To perform the action in the same file use "-i"
    [root@golinuxhub ~]# sed -i '/^$/d' /tmp/file

    [root@golinuxhub ~]# cat /tmp/file
    This is line one
    This is line two
    This is line three
    This is line four


    I hope the article was useful.















    Deepak Prasad

    Deepak Prasad is an anonymous techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+

    Do you also have something to share here?

    Become an author and be a part of our GoLinuxHub Team, Click here for more information
    sed: delete all blank lines from a text file sed: delete all blank lines from a text file Reviewed by Deepak Prasad on Monday, September 11, 2017 Rating: 5

    No comments:

    Powered by Blogger.