How to delete empty lines and lines only with white spaces from a file

Home Questions How to delete empty lines and lines only with white spaces from a file

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Vijaya Ban 2 years ago.

  • Author
    Posts
  • #6692 Reply

    admin
    Keymaster
    Online
    Topics: 65
    Replies: 65

    Below command helps me to remove only blank or empty lines from a file. Bit it not removes a line with white space.

    sed '/^$/d' filename > filename.temp
  • #6780 Reply

    Vijaya Ban
    Participant
    Offline
    Topics: 1
    Replies: 1

    Try:

    sed '/^ *$/d' filename > filename.tmp
    filename.tmp > filename

    This will remove blank lines and lines with only white spaces from a file.

Reply To: How to delete empty lines and lines only with white spaces from a file

You can use BBCodes to format your content.
Your account can't use Advanced BBCodes, they will be stripped before saving.

Your information: