help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stop printing when non-comment lines are reached


From: alex xmb ratchev
Subject: Re: Stop printing when non-comment lines are reached
Date: Thu, 2 Feb 2023 09:42:02 +0100

just wanna say , /beginmatch/ , /endmatch/ .. works also in awk

On Wed, Feb 1, 2023, 7:20 PM Hans Lonsdale <hanslonsdale@mailfence.com>
wrote:

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]