Sed - inserting spaces

December 2016


  • Insert a blank line after each sentence (punctuated by a carriage return)
    • sed G file.txt
  • Insert a blank line after each sentence (punctuated by a carriage return), without taking into account the existing white lines:
    • sed '/^$/d;G' file.txt
  • Add two blank lines after each sentence (punctuated by a carriage return)
    • sed 'G;G' file.txt
  • Insert a blank line before each line "matched" by / pattern /"(" pattern "can be a regular expression)
    • sed '/End/{x;p;x}' file.txt
  • Insert a blank line after each line "matched" by / pattern /"(" pattern "can be a regular expression)
    • s
      ed '/Start/G' file.txt
  • Insert a blank line before and after each line "matched" by / pattern /"(" pattern "can be a regular expression)
    • sed '/Stream Editor/{x;p;x;G}' file.txt

Related :

This document entitled « Sed - inserting spaces » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.