diff options
| author | Abigail <abigail@abigail.be> | 2021-02-04 21:46:20 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-02-05 18:39:12 +0100 |
| commit | 686952c9bef6e28629e4b31365aa3bc4e1b8e3d0 (patch) | |
| tree | a4d0d5ea1ca46dcf231d948ec0c4cfc2d17ae3b1 | |
| parent | e1229c9533942e3eb7b552111ce6e2d2d4ab421d (diff) | |
| download | perlweeklychallenge-club-686952c9bef6e28629e4b31365aa3bc4e1b8e3d0.tar.gz perlweeklychallenge-club-686952c9bef6e28629e4b31365aa3bc4e1b8e3d0.tar.bz2 perlweeklychallenge-club-686952c9bef6e28629e4b31365aa3bc4e1b8e3d0.zip | |
AWK solution for week 98, part 1
| -rw-r--r-- | challenge-098/abigail/awk/ch-1.awk | 41 |
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) +} |
