Advertisement
devinteske

RE test for different awk versions

Apr 1st, 2020
3,478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.20 KB | None | 0 0
  1. #!/usr/bin/awk -f
  2.  
  3. #
  4. # Test several regex patterns against printable ASCII characters
  5. # Related to https://twitter.com/freebsdfrau/status/1245253969447809024?s=20
  6. #
  7. # Original: https://gist.github.com/s-leroux/f6fd8b432f56579f7ad08f964c9f69ff
  8. #
  9.  
  10. BEGIN {
  11.         # input   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
  12.         expect = "............x..xxxxxxxxxx.......xxxxxxxxxxxxxxxxxxxxxxxxxx"
  13.  
  14.         # input (cont.)  [\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  15.         expect = expect "....x.xxxxxxxxxxxxxxxxxxxxxxxxxx...."
  16.  
  17.         width = 12
  18.         green = 32
  19.         red = 31
  20.  
  21.         test["[-_[:alnum:]]"]
  22.         test["[-[:alnum:]_]"]
  23.         test["[_[:alnum:]-]"]
  24.         test["[[:alnum:]_-]"]
  25.         test["[a-zA-Z0-9_-]"]
  26.         test["[-_a-zA-Z0-9]"]
  27.         test["[-a-zA-Z0-9_]"]
  28.         test["[_a-zA-Z0-9-]"]
  29.  
  30.         for (i = 33; i <= 126; i++) {
  31.                 input = input (c = sprintf("%c", i))
  32.                 for (re in test) m[re] = m[re] (match(c, re) ? "x" : ".")
  33.         }
  34.  
  35.         printf "%-*s %s\n", width + 1, "input", input
  36.         for (re in m) printf "%-*s \033[%sm%s\033[m\n", width, re,
  37.                 (m[re] == expect ? green : red), m[re]
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement