aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-07-02 02:13:25 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-07-02 02:13:25 +1200
commitca3cc521dd28478c9b51b7c3d9a176835cfa6fa9 (patch)
tree5b4e733d72785af750fa4cc164e85cff5f3b89b8
parentBreak pks(6df) and philsay(6df) in two (diff)
downloaddotfiles-ca3cc521dd28478c9b51b7c3d9a176835cfa6fa9.tar.gz
dotfiles-ca3cc521dd28478c9b51b7c3d9a176835cfa6fa9.zip
Remove POSIX char classes from Awk
I forgot that Debian's awk(1) is still a mawk that doesn't implement e.g. [:alpha:]
-rw-r--r--bin/mw.awk2
-rw-r--r--bin/onl.awk4
-rw-r--r--foo0
-rw-r--r--games/drakon.awk2
-rw-r--r--games/pks.awk4
5 files changed, 6 insertions, 6 deletions
diff --git a/bin/mw.awk b/bin/mw.awk
index 48f45fb1..95d70c32 100644
--- a/bin/mw.awk
+++ b/bin/mw.awk
@@ -5,6 +5,6 @@ BEGIN {
}
{
for (i = 1; i <= NF; i++)
- if ($i ~ /[[:alpha:]]/)
+ if ($i ~ /[a-zA-Z]/)
print $i
}
diff --git a/bin/onl.awk b/bin/onl.awk
index 466b8451..15e4f46d 100644
--- a/bin/onl.awk
+++ b/bin/onl.awk
@@ -2,8 +2,8 @@
# For each line of input ...
{
- # Strip out non-printable characters and rebuild the fields
- gsub(/[[:cntrl:]]/, "")
+ # Strip out whitespace characters and rebuild the fields
+ gsub(/[\n\t\r ]+/, "")
# Print each field, without a newline; add a leading space if it's not the
# very first one
diff --git a/foo b/foo
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/foo
diff --git a/games/drakon.awk b/games/drakon.awk
index ce619585..ebca4e95 100644
--- a/games/drakon.awk
+++ b/games/drakon.awk
@@ -6,7 +6,7 @@
tog = 0
for (i = 1; i <= len; i++) {
chr = substr($0, i, 1)
- if (chr ~ /[[:alpha:]]/)
+ if (chr ~ /[a-zA-Z]/)
chr = (tog = !tog) ? tolower(chr) : toupper(chr)
lin = lin chr
}
diff --git a/games/pks.awk b/games/pks.awk
index 06aad75f..028e471f 100644
--- a/games/pks.awk
+++ b/games/pks.awk
@@ -23,7 +23,7 @@ BEGIN {
# Iterate over the lines, randomly assigning the first field of each one with a
# decreasing probability; this method allows a single pass over the input,
# though it requires a lot of random numbers
-$1 ~ /[[:alpha:]]/ && rand() * ++n < 1 { wr = $1 }
+$1 ~ /[a-zA-Z]/ && rand() * ++n < 1 { wr = $1 }
# Ha, ha! Conclusion!
END {
@@ -33,7 +33,7 @@ END {
exit 1
# Strip trailing possessives and punctuation
- sub(/[^[:alpha:]]+s*$/, "", wr)
+ sub(/[^a-zA-Z]+s*$/, "", wr)
# Two or three "ha"s? Important decisions here folks
hr = int(rand()*2+1)