From 686952c9bef6e28629e4b31365aa3bc4e1b8e3d0 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 4 Feb 2021 21:46:20 +0100 Subject: AWK solution for week 98, part 1 --- challenge-098/abigail/awk/ch-1.awk | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 challenge-098/abigail/awk/ch-1.awk 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) +} -- cgit