[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Stop printing when non-comment lines are reached
From: |
Hans Lonsdale |
Subject: |
Stop printing when non-comment lines are reached |
Date: |
Wed, 1 Feb 2023 15:54:51 +0100 (CET) |
I am printing between sections of the following form
---------
## FAML [ASMB] keyword,keyword
## Some text
## END OF FAML [ASMB]
---------
I have encountered a problem that occurs when "## END OF FAML [ASMB]" is not
reached.
I want to stop as soon as lines not starting with comment characters "##" are
encountered.
For instance, I want to stop upon reaching "Some code" even though it did not
find
"## END OF FAML [ASMB]" because the line does not start with "##".
---------
## FAML [ASMB] keyword,keyword
## Some text
## End OF FAL
Some code
--------
This is the implementation
spc='[[:space:]]*'
gph="[[:graph:]]+"
cmt='\/\/'
ebl='\['
ebr='\]'
local pn_ere="^[[:space:]]*([#;!]+|@c|${cmt})[[:space:]]+"
local kys="(([^,]+)(,[^,]+)*)?"
nfaml=${faml:-"[[:graph:]]+"}
nasmb=${asmb:-"[[:graph:]]+"}
beg_ere="${pn_ere}${nfaml} ${ebl}${nasmb}${ebr}${spc}${kys}$"
end_ere="${pn_ere}END OF ${nfaml} ${ebl}${nasmb}${ebr}${spc}$"
sed -E -n "/$beg_ere/,/$end_ere/ {
/$end_ere/z; s/$pn_ere// ; p
}" "$filename"
--
Sent with https://mailfence.com
Secure and private email
- Stop printing when non-comment lines are reached,
Hans Lonsdale <=