aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-110/abigail/README.md1
-rw-r--r--challenge-110/abigail/lua/ch-2.lua32
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md
index 33d02ed67b..c8b41d05d1 100644
--- a/challenge-110/abigail/README.md
+++ b/challenge-110/abigail/README.md
@@ -79,6 +79,7 @@ sex,m,m,f,f
* [AWK](awk/ch-2.awk)
* [Bash](bash/ch-2.ch)
* [C](c/ch-2.c)
+* [Lua](lua/ch-2.lua)
* [Perl](perl/ch-2.pl)
### Blog
diff --git a/challenge-110/abigail/lua/ch-2.lua b/challenge-110/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..627fb8176a
--- /dev/null
+++ b/challenge-110/abigail/lua/ch-2.lua
@@ -0,0 +1,32 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+--
+-- Read in the input, split each line on commas, and create
+-- the ouput strings from the split field.
+--
+local output = {}
+for line in io . lines () do
+ local i = 1
+ for field in line : gmatch ("[^,\n]+")
+ do if output [i] == nil
+ then output [i] = ""
+ end
+ output [i] = output [i] .. field .. ","
+ i = i + 1
+ end
+end
+
+--
+-- Print the output
+--
+for _, line in ipairs (output)
+do print (line : sub (1, -2))
+end