diff options
| author | Abigail <abigail@abigail.be> | 2021-04-29 02:30:56 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-04-29 02:30:56 +0200 |
| commit | c7a884422fee8df483e3e88abdf372b1ebbe7415 (patch) | |
| tree | c89acf62f95021f0e145ee93a38df3feb2cb3fad | |
| parent | d5c2a31cd0d4208c124d6f1306b9adf945a5baac (diff) | |
| download | perlweeklychallenge-club-c7a884422fee8df483e3e88abdf372b1ebbe7415.tar.gz perlweeklychallenge-club-c7a884422fee8df483e3e88abdf372b1ebbe7415.tar.bz2 perlweeklychallenge-club-c7a884422fee8df483e3e88abdf372b1ebbe7415.zip | |
Bash solution for week 110, part 2
| -rw-r--r-- | challenge-110/abigail/README.md | 2 | ||||
| -rw-r--r-- | challenge-110/abigail/bash/ch-2.sh | 30 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md index bbba807500..c8c826c8cd 100644 --- a/challenge-110/abigail/README.md +++ b/challenge-110/abigail/README.md @@ -76,6 +76,8 @@ sex,m,m,f,f ### Solutions +* [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.ch) * [Perl](perl/ch-2.pl) ### Blog diff --git a/challenge-110/abigail/bash/ch-2.sh b/challenge-110/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..38dd956446 --- /dev/null +++ b/challenge-110/abigail/bash/ch-2.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh < input-file +# + + +declare -a out + +# +# Read in the data, add each field to the appropriate output string +# +IFS="," +while read -a chunks +do for ((i = 0; i < ${#chunks[@]}; i ++)) + do out[$i]=${out[$i]}${chunks[$i]}, + done +done + +# +# Print the output string, dropping the final comma +# +IFS="" +for ((i = 0; i < ${#out[@]}; i ++)) +do echo ${out[$i]:0:-1} +done |
