summaryrefslogtreecommitdiff
path: root/awk/utils.awk
diff options
context:
space:
mode:
Diffstat (limited to 'awk/utils.awk')
-rw-r--r--awk/utils.awk23
1 files changed, 23 insertions, 0 deletions
diff --git a/awk/utils.awk b/awk/utils.awk
new file mode 100644
index 0000000..00045de
--- /dev/null
+++ b/awk/utils.awk
@@ -0,0 +1,23 @@
+## Helper functions
+
+# Remove all whitespace in str
+function trim(str) {
+ gsub(/[ \t]/, "", str);
+ return str;
+}
+
+# Remove all whitespace around str
+function trim_surrounding(str) {
+ gsub(/^[ \t]*/, "", str);
+ gsub(/[ \t]*$/, "", str);
+ return str;
+}
+
+# Time n days before the current time
+function time_days_ago(n) {
+ return strftime("%FT%T", systime() - 24 * 60 * 60 * n, 1);
+}
+
+function or_default(var, def) {
+ return var ? var : def;
+}