From 222d2dc7f3ec3ec9ce254a70f386e84804f4be39 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 23 Oct 2023 14:59:32 +0300 Subject: [s2] POSIX Reworked title, descr and words variables to be assigned from a single awk script Faster than before and more portable --- csg | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/csg b/csg index c145ca2..803ac74 100755 --- a/csg +++ b/csg @@ -217,16 +217,18 @@ transform-file() { local scripts="$2" # Gets special information from the file - local title="$($CSG_AWK -v titlef="$TITLEF" ' - /^# / { + local title descr words + { read -r title; read -r descr; read -r words; } << EOF +$($CSG_AWK -v titlef="$TITLEF" ' + title == "" && /^# / { # Remove first field $1 = ""; sub(FS, "") # Output title - sub(/.*/, titlef); print - exit - }' "$file")" - local descr="$($CSG_AWK ' - /^[[:alpha:]]/ { + sub(/.*/, titlef) + title = $0 + next + } + stopdesc == 0 && /^[[:alpha:]]/ { startedGathering = 1 # Take only anchor text gsub(/\]\([^)]*\)/, "") @@ -237,13 +239,14 @@ transform-file() { # Trim line to 200 characters if (length(desc) > 200) { desc = substr(desc, 1, 197) "..." - exit + stopdesc = 1 } } startedGathering && /^$/ { exit } - END { print desc }' "$file")" - local words="$($CSG_AWK '{total += NF} END{print total}' "$file")" - local timestamps=($($CSG_AWK -v file="$outf" ' + { words += NF } + END { print title ORS desc ORS words }' "$file") +EOF + BEGIN { FS = "\t" } $1 == file { print $2 -- cgit v1.3.1-23-gd82d