【发布时间】:2021-12-19 00:12:10
【问题描述】:
我有这个 bash 函数可以打印 Mode: org 和 # End of org 之间的行。我希望匹配的部分用空行分隔。
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"
}
这是输入
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
【问题讨论】:
-
请将该示例输入的所需输出(无描述、无图像、无链接)添加到您的问题(无评论)。