• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 28320
210
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.
 
Grow your own food... or this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic