commit 4247fe8feea09744f1805e3979abc9ed27192f35
parent 33d4d8b7c0fe27b8903502fe2ac3df4c136fa2ac
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Mon, 30 Aug 2021 16:11:53 -0700
Add script to write formatted sfeed(5) entries to the filesystem
Diffstat:
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/local/bin/.local/bin/sfextract b/local/bin/.local/bin/sfextract
@@ -0,0 +1,39 @@
+#!/usr/bin/awk -f
+# Copyright 2021 Jacob R. Edwards
+# License: GPLv3
+# sfextract -- Write formatted sfeed entries to the filesystem
+
+# strftime is an extention
+function Strftime(fmt, elapsed) {
+ cmd = sprintf("date -r '%d' '+%s'", elapsed, fmt);
+ cmd | getline date;
+ close(cmd);
+ return date;
+}
+
+BEGIN {
+ FS = " ";
+ line = "\
+";
+ name = 2;
+ text = 4;
+ time = 1;
+ type = 5;
+}
+
+{
+ dir = Strftime("%F/%R", $time);
+ if (system("mkdir -p " dir))
+ exit 1;
+
+ gsub("/", "", $name);
+ gsub("\"", "''", $name);
+ gsub("\\\\t", " ", $text);
+ gsub("\\\\n", line, $text);
+
+ fmt = (($type == "html") ? "htmlfmt" : "fmt");
+ cmd = sprintf("%s > \"%s/%s\"", fmt, dir, $name);
+
+ print $text | cmd;
+ close(cmd);
+}