[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Printing TITLE, SUBTITLE, and KEYWORDS
From: |
Dennis Williamson |
Subject: |
Re: Printing TITLE, SUBTITLE, and KEYWORDS |
Date: |
Fri, 3 Feb 2023 10:25:25 -0600 |
On Fri, Feb 3, 2023, 9:34 AM Hans Lonsdale <hanslonsdale@mailfence.com>
wrote:
> I have changed to using awk as the way to print sections defined by the
> following structure
>
> ## NFAML [NASMB] KEYWORDS
> ## BODY (can include empty lines)
> ## END OF NFAML [NASMB]
>
> Am trying to print TITLE, SUBTITLE and the KEYWORDS array, but not getting
> them printed.
>
>
> spc='[[:space:]]*'
> ebl='\\[' # awk needs it for applying \[
> ebr='\\]' # awk needs it for applying \]
> pn_ere='^[[:space:]]*([#;!]+|@c|//)[[:space:]]+'
>
> ## :- modifier, use GPH if parameters are unset or empty (null).
> nfaml=${faml:-"[[:graph:]]+"} # Use GPH if FAML null ("" or '')
> nasmb=${asmb:-"[[:graph:]]+"} # Use GPH if ASMB null ("" or '')
>
> cmt='\/\/' ; ebl='\[' ; ebr='\]' # for sed to apply // ] [
> spc='[[:space:]]*' ; gph="[[:graph:]]+"
>
> local kys=".*"
> local pn_ere="^[[:space:]]*([#;!]+|@c|${cmt})[[:space:]]+"
> beg_ere="${pn_ere}(${nfaml}) ${ebl}(${nasmb})${ebr}${spc}(${kys})$"
> end_ere="${pn_ere}END OF ${nfaml} ${ebl}${nasmb}${ebr}${spc}$"
>
>
> awk -v beg_ere="$beg_ere" -v pn_ere="$pn_ere" -v end_ere="$end_ere" \
> '$0 ~ beg_ere {
> title=gensub(beg_ere, "\\1", "g", $0);
> subtitle=gensub(beg_ere, "\\2", "g", $0);
> keywords=gensub(beg_ere, "\\3", "g", $0);
> n = split(keywords, kaggr, ",");
> print "Title: " title;
> print "Subtitle: " subtitle;
> print "Keywords: " keywords;
> for (i = 0; ++i <= n;)
> print i, kaggr[i]
> next
> }
> $0 ~ pn_ere {
> $0=gensub(pn_ere, "", "g", $0);
> print $0
> }
> $0 ~ end_ere {
> print ""
> }
> ' "$filename"
>
>
> --
> Sent with https://mailfence.com
> Secure and private email
>
>
You're reassignment ebl and ebr.
AWK isn't Bash. Please take your questions to an AWK or other list.
- Printing TITLE, SUBTITLE, and KEYWORDS, Hans Lonsdale, 2023/02/03
- Re: Printing TITLE, SUBTITLE, and KEYWORDS,
Dennis Williamson <=
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Greg Wooledge, 2023/02/03
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Hans Lonsdale, 2023/02/04
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Greg Wooledge, 2023/02/04
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Hans Lonsdale, 2023/02/05