• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

How sed inserting one blank line only if precede non blank line

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How sed inserting one blank line as this keep failing:


In order to insert one blank line right after line not followed by blank line, then keep the rest as is
E.g. below is qualified to be worked on:



Fail too by using i.e.
As it inserts two blank line:



Please help guide correct path, thanks much
 
Saloon Keeper
Posts: 27276
193
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
welcome to the Ranch, almahoom!

Putting control characters into regexes on Linux/Unix command lines can be maddening. More so since the rules change between raw command-line input and scripts, much less between different unix-like systems and shells.

But I found this discussion helpful: https://stackoverflow.com/questions/45620124/insert-blank-line-before-line-matching-pattern-in-sed

On my Linux system, this particular expression worked like a charm:

where the a blank line gets inserted before the line that contains "happy" in the file named test.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic