aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-098/abigail/awk/ch-1.awk41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-098/abigail/awk/ch-1.awk b/challenge-098/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..ac53032a93
--- /dev/null
+++ b/challenge-098/abigail/awk/ch-1.awk
@@ -0,0 +1,41 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+
+#
+# If we haven't ready in the content of "filename" yet, do so,
+# and store it into an array, indexed by the filename.
+#
+# Remove the first amount characters of the stored content, and
+# return it.
+#
+function readN(filename, amount) {
+ if (!content [filename]) {
+ old_rs = RS
+ #
+ # We want to read the entire file, so we pick a
+ # character which should not be present in the file
+ # as the record separator.
+ #
+ RS = "\000"
+ getline content [filename] < filename
+ #
+ # Restore the record separator.
+ #
+ RS = old_rs
+ }
+ r = substr (content [filename], 1, amount)
+ content [filename] = substr (content [filename], amount + 1)
+ return r
+}
+
+{
+ print readN($1, $2)
+}