Article 5RH4M Introducing blank lines separating matched sections

Introducing blank lines separating matched sections

by
Faki
from LinuxQuestions.org on (#5RH4M)
I have this bash function that prints lines between `Mode: org` and `# End of org`. I would like for matched sections to be separated by a blank line.

Code:capture ()
{
local efile="$1"

local charcl begorg endorg
charcl_ere='^[[:space:]]*([#;!]+|@c|\/\/)[[:space:]]*'
charcl_bre='^[[:space:]]*\([#;!]\+\|@c\|\/\/\)[[:space:]]*'

begorg="${charcl_bre}"'Mode: org$'
endorg="${charcl_bre}"'# End of org$'

mdr='^Mode: org$' ; edr='^# End of org$'

sed -n "/$begorg/,/$endorg/ s/$charcl_bre//p" "$efile" |
sed "/$mdr\|$edr/d"
}
This is the input

Code:cat /home/flora/docs/recnotes.txt
## Mode: org
# Assigns shell positional parameters or changes the values of shell
# options. The -- option assigns the positional parameters to the
# arguments of {set}, even when some of them start with an option
# prefix `-'.
## # End of org

;; Mode: org
; Assigns shell positional parameters or changes the values of shell
; options. The -- option assigns the positional parameters to the
; arguments of {set}, even when some of them start with an option
; prefix `-'.
;; # End of org

@c Mode: org
@c Assigns shell positional parameters or changes the values of shell
@c options. The -- option assigns the positional parameters to the
@c arguments of {set}, even when some of them start with an option
@c prefix `-'.
@c # End of orglatest?d=yIl2AUoC8zA latest?i=dc29ZrMkeXk:B8zwu5XZ_1k:F7zBnMy latest?i=dc29ZrMkeXk:B8zwu5XZ_1k:V_sGLiP latest?d=qj6IDK7rITs latest?i=dc29ZrMkeXk:B8zwu5XZ_1k:gIN9vFwdc29ZrMkeXk
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments