[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Printing TITLE, SUBTITLE, and KEYWORDS
From: |
Hans Lonsdale |
Subject: |
Printing TITLE, SUBTITLE, and KEYWORDS |
Date: |
Fri, 3 Feb 2023 13:55:29 +0100 (CET) |
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
- Printing TITLE, SUBTITLE, and KEYWORDS,
Hans Lonsdale <=
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Dennis Williamson, 2023/02/03
- 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