logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

wc.t (1686B)


  1. #!/usr/bin/env cram
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. $ export PATH="$TESTDIR/../cmd:$PATH"
  5. $ test "$(command -v wc)" = "$TESTDIR/../cmd/wc"
  6. $ export LANG=C.UTF-8 LC_ALL=C.UTF-8
  7. $ printf 'a b c' | wc
  8. \s*0\s*3\s*5\s* (re)
  9. $ printf 'a\nb\nc\n' | wc
  10. \s*3\s*3\s*6\s* (re)
  11. $ printf 'a\nb\nc\n' | wc -clw
  12. \s*3\s*3\s*6\s* (re)
  13. $ printf 'a\nbb\nccc\n' | wc
  14. \s*3\s*3\s*9\s* (re)
  15. $ printf 'a\nbb\nccc\n' | wc -clw
  16. \s*3\s*3\s*9\s* (re)
  17. $ printf 'я нет 草' | wc -m
  18. \s*7\s* (re)
  19. $ printf 'я нет 草' | wc -mw
  20. \s*3\s*7\s* (re)
  21. $ printf 'я нет 草' | wc -mlw
  22. \s*0\s*3\s*7\s* (re)
  23. $ wc <&-
  24. wc: Failed reading from file '<stdin>': Bad file descriptor
  25. [1]
  26. $ wc -m <&-
  27. wc: Failed reading from file '<stdin>': Bad file descriptor
  28. [1]
  29. $ echo -n >empty
  30. $ wc empty
  31. 0 0 0 empty
  32. $ wc /var/empty/e/no/ent
  33. wc: Failed opening file '/var/empty/e/no/ent': No such file or directory
  34. [1]
  35. Formatting with reduced counts
  36. $ echo | wc -l
  37. 1
  38. $ echo a | wc -l
  39. 1
  40. $ echo | wc -c
  41. 1
  42. $ echo a | wc -c
  43. 2
  44. $ echo | wc -w
  45. 0
  46. $ echo a | wc -w
  47. 1
  48. $ echo | wc -cl
  49. 1 1
  50. $ echo a | wc -cl
  51. 1 2
  52. $ wc -c empty
  53. 0 empty
  54. $ wc -cl empty
  55. 0 0 empty
  56. $ wc -w empty
  57. 0 empty
  58. Total when multiple files are specified
  59. $ echo foo | wc empty -
  60. 0 0 0 empty
  61. 1 1 4
  62. 1 1 4 total
  63. $ printf 'foo bar\n' > foobar
  64. $ wc foobar empty
  65. 1 2 8 foobar
  66. 0 0 0 empty
  67. 1 2 8 total
  68. $ printf 'foot bart\n' > footbart
  69. $ wc -c foobar footbart empty
  70. 8 foobar
  71. 10 footbart
  72. 0 empty
  73. 18 total
  74. $ rm foobar footbart empty
  75. $ find .
  76. .