aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-04-26 19:20:18 +0200
committerAbigail <abigail@abigail.be>2021-04-26 19:20:18 +0200
commitee402dd3d5c6c41246f1d595a0b50f7c23ea7165 (patch)
tree0e6c391110cd9770e5178e45583cb481726ba1b9
parenteaafeb924c8473172e139a8a92539b504550429b (diff)
downloadperlweeklychallenge-club-ee402dd3d5c6c41246f1d595a0b50f7c23ea7165.tar.gz
perlweeklychallenge-club-ee402dd3d5c6c41246f1d595a0b50f7c23ea7165.tar.bz2
perlweeklychallenge-club-ee402dd3d5c6c41246f1d595a0b50f7c23ea7165.zip
Bash solution for week 110, part 1
-rw-r--r--challenge-110/abigail/README.md1
-rw-r--r--challenge-110/abigail/bash/ch-1.sh25
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md
index 6e98908e45..051aef0d33 100644
--- a/challenge-110/abigail/README.md
+++ b/challenge-110/abigail/README.md
@@ -42,6 +42,7 @@ can completly ignore any white space in the input.
### Solutions
[AWK](awk/ch-1.awk)
+[Bash](bash/ch-1.sh)
[Perl](perl/ch-1.pl)
### Blog
diff --git a/challenge-110/abigail/bash/ch-1.sh b/challenge-110/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..8038708208
--- /dev/null
+++ b/challenge-110/abigail/bash/ch-1.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+IFS="" # This way, we keep the spaces as is.
+
+valid="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
+
+while read line
+do raw=${line// } # Remove spaces
+ raw=${raw/#+/00} # Replace leading + with 00
+ raw=${raw/#([0-9][0-9])/0000} # Replace leading (NN) with 0000
+ left=${raw/$valid} # Remove 14 digits
+ if [ "X$left" == "X" ] # If nothing left, the input is valid
+ then echo $line # Print it
+ fi
+done