Article 5RF1E Using comment symbol for matching comment sections

Using comment symbol for matching comment sections

by
Faki
from LinuxQuestions.org on (#5RF1E)
I have the following bash function to extract sections between `## Mode: org` and `## # End of org`, using `#` as the comment character.

I would like to enable other comment characters instead of handling only `#`. Using a Character Class `[#;c!C]` could be a good plan.

I also want to allow a user-defined literal string for the texinfo comment identifier `@c`.

Code:
capture ()
{
local efile="$1"
begorg='^[[:space:]]*## Mode: org$'
endorg='^[[:space:]]*## # End of org$'
awk -v bego="$begorg" -v endo="$endorg" \
'$0 ~ bego { found=1; next }
$0 ~ endo { found=0; }
found { sub(/^[[:space:]]*#+[[:space:]]*/,""); print }' "$efile"
}latest?d=yIl2AUoC8zA latest?i=785piN8Fp4s:pY8pqwQlXnc:F7zBnMy latest?i=785piN8Fp4s:pY8pqwQlXnc:V_sGLiP latest?d=qj6IDK7rITs latest?i=785piN8Fp4s:pY8pqwQlXnc:gIN9vFw785piN8Fp4s
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