From c7a884422fee8df483e3e88abdf372b1ebbe7415 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 29 Apr 2021 02:30:56 +0200 Subject: Bash solution for week 110, part 2 --- challenge-110/abigail/README.md | 2 ++ challenge-110/abigail/bash/ch-2.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 challenge-110/abigail/bash/ch-2.sh 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 -- cgit