top of page

Sed Command to remove blank lines from a file in Unix .

  • Writer: Jatin Madaan
    Jatin Madaan
  • Apr 28, 2019
  • 1 min read

Let's say we have a file - date.txt which has 5 lines in total out of which 2 lines are blank .


We now need to remove blank lines so that space can be saved on disk (for very large files ) or for some other reasons.


This can easily be done using Sed command :


sed '/^$/d' date.txt


Here ^$ - means blank line , so search for blank lines and delete using d command of vi editor.



This is a very simple yet useful command.



Comments


  • linkedin

©2019 by Jatinmadaan

bottom of page