aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-110/abigail/README.md2
-rw-r--r--challenge-110/abigail/bash/ch-2.sh30
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