diff options
| -rw-r--r-- | challenge-098/abigail/README.md | 2 | ||||
| -rw-r--r-- | challenge-098/abigail/bash/ch-1.sh | 54 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-098/abigail/README.md b/challenge-098/abigail/README.md index 2d3ffae7bb..d550cdd363 100644 --- a/challenge-098/abigail/README.md +++ b/challenge-098/abigail/README.md @@ -53,6 +53,8 @@ Output: ~~~~ ### Solutions +* [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.sh) * [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-098/abigail/bash/ch-1.sh b/challenge-098/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..ebd4353079 --- /dev/null +++ b/challenge-098/abigail/bash/ch-1.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# +# Each line of input consists of a filename and an amount +# of characters to read. +# + +# +# Create associative arrays +# +declare -A content +declare -A read + +function readN { + # + # Read arguments + # + filename=$1 + amount=$2 + + # + # First time? Then read in file. + # + if [ "${read[$filename]}" != "1" ] + then read[$filename]=1 + content[$filename]=$(<$filename) + fi + + # + # Leading $amount characters + # + r=${content[$filename]:0:$amount} + + # + # Remove $amount characters + # + content[$filename]=${content[$filename]:$amount} + + echo $r +} + + +# +# Read input, call readN +# +while read filename amount +do readN $filename $amount +done |
