diff options
| Commit | 222d2dc7f3ec3ec9ce254a70f386e84804f4be39 (patch) | |
|---|---|---|
| Author | 2023-10-23 14:59:32 +0300 | |
| Committer | 2023-10-23 15:00:04 +0300 | |
| Files | c694a49a2aa5430bee6219eefdb8b5999ebc3241 | |
| csg-222d2dc7f3ec3ec9ce254a70f386e84804f4be39.tar csg-222d2dc7f3ec3ec9ce254a70f386e84804f4be39.tar.gz csg-222d2dc7f3ec3ec9ce254a70f386e84804f4be39.zip | ||
| Parent | 9f6222ac1bf8c2d7ddeb45bf61dcc2a87f7143ee (diff) | |
[s2] POSIX Reworked title, descr and words variables to be assigned from a single awk script
Faster than before and more portable
1 files changed, 14 insertions, 11 deletions
| -rwxr-xr-x | csg | 25 |
@@ -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 |
