Введение пустых строк между совпадающими разделами

У меня есть следующая функция bash, которая использует sed для извлечения разделов, расположенных между ## Mode: org и ## # Конец org, где # — символ комментария. Наконец, я удаляю символ комментария и любые пробелы.

Это мой ввод

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 org

Вот функция bash с реализацией в sed.

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"
}

Изначально у меня были две команды as

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

, которые не расширяли переменную charcl_bre.

Вывод:

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 `-'.
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 `-'.
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 `-'.

Я бы хотел, чтобы между разделами была пустая строка.

-2
задан 3 November 2021 в 05:17

0 ответов

Другие вопросы по тегам:

Похожие вопросы: