A book about the command line for humans.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
5.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
  1. 9. a miscellany of tools and techniques
  2. =======================================
  3. dict
  4. ----
  5. Want to know the definition of a word, or find useful synonyms?
  6. $ dict concatenate | head -10
  7. 4 definitions found
  8. From The Collaborative International Dictionary of English v.0.48 [gcide]:
  9. Concatenate \Con*cat"e*nate\ (k[o^]n*k[a^]t"[-e]*n[=a]t), v. t.
  10. [imp. & p. p. {Concatenated}; p. pr. & vb. n.
  11. {Concatenating}.] [L. concatenatus, p. p. of concatenare to
  12. concatenate. See {Catenate}.]
  13. To link together; to unite in a series or chain, as things
  14. depending on one another.
  15. aspell
  16. ------
  17. Need to interactively spell-check your presentation notes?
  18. $ aspell check presentation
  19. Just want a list of potentially-misspelled words in a given file?
  20. <!-- exec -->
  21. $ aspell list < ../literary_environment/index.md | sort | uniq -ci | sort -nr | head -5
  22. 40 td
  23. 24 Veselka
  24. 17 Reuel
  25. 16 Brunner
  26. 15 Tiptree
  27. <!-- end -->
  28. mostcommon
  29. ----------
  30. Something like that last sequence sure does seem to show up a lot in my work:
  31. Spit out the _n_ most common lines in the input, one way or another. Here's
  32. a little script to be less repetitive about it.
  33. <!-- exec -->
  34. $ aspell list < ../literary_environment/index.md | ./mostcommon -i -n5
  35. 40 td
  36. 24 Veselka
  37. 17 Reuel
  38. 16 Brunner
  39. 15 Tiptree
  40. <!-- end -->
  41. This turns out to be pretty simple:
  42. <!-- exec -->
  43. $ cat ./mostcommon
  44. #!/usr/bin/env bash
  45. # Optionally specify number of lines to show, defaulting to 10:
  46. TOSHOW=10
  47. CASEOPT=""
  48. while getopts ":in:" opt; do
  49. case $opt in
  50. i)
  51. CASEOPT="-i"
  52. ;;
  53. n)
  54. TOSHOW=$OPTARG
  55. ;;
  56. \?)
  57. echo "Invalid option: -$OPTARG" >&2
  58. exit 1
  59. ;;
  60. :)
  61. echo "Option -$OPTARG requires an argument." >&2
  62. exit 1
  63. ;;
  64. esac
  65. done
  66. # sort and then uniqify STDIN,
  67. # sort numerically on the first field,
  68. # chop off everything but $TOSHOW lines of input
  69. sort < /dev/stdin | uniq -c $CASEOPT | sort -k1 -nr | head -$TOSHOW
  70. <!-- end -->
  71. Notice, though, that it doesn't handle opening files directly. If you wanted
  72. to find the most common lines in a file with it, you'd have to say something
  73. like `mostcommon < filename` in order to redirect the file to `mostcommon`'s
  74. input.
  75. Also notice that most of the script is boilerplate for handling a couple of
  76. options. The work is all done in a oneliner. Worth it? Maybe not, but an
  77. interesting exercise.
  78. cal and ncal
  79. ------------
  80. Want to know what the calendar looks like for this month?
  81. $ cal
  82. April 2014
  83. Su Mo Tu We Th Fr Sa
  84. 1 2 3 4 5
  85. 6 7 8 9 10 11 12
  86. 13 14 15 16 17 18 19
  87. 20 21 22 23 24 25 26
  88. 27 28 29 30
  89. How about for September, 1950, in a more compact format?
  90. <!-- exec -->
  91. $ ncal -m9 1950
  92. September 1950
  93. Su 3 10 17 24
  94. Mo 4 11 18 25
  95. Tu 5 12 19 26
  96. We 6 13 20 27
  97. Th 7 14 21 28
  98. Fr 1 8 15 22 29
  99. Sa 2 9 16 23 30
  100. <!-- end -->
  101. Need to know the date of Easter this year?
  102. <!-- exec -->
  103. $ ncal -e
  104. April 20 2014
  105. <!-- end -->
  106. seq
  107. ---
  108. Need the numbers 1-5?
  109. <!-- exec -->
  110. $ seq 1 5
  111. 1
  112. 2
  113. 3
  114. 4
  115. 5
  116. <!-- end -->
  117. shuf
  118. ----
  119. Want to shuffle some lines?
  120. <!-- exec -->
  121. $ seq 1 5 | shuf
  122. 2
  123. 1
  124. 4
  125. 3
  126. 5
  127. <!-- end -->
  128. ptx
  129. ---
  130. Want to make a [permuted index][kwic] of some phrase?
  131. <!-- exec -->
  132. $ echo 'i like american music' | ptx
  133. i like american music
  134. i like american music
  135. i like american music
  136. i like american music
  137. <!-- end -->
  138. figlet
  139. ------
  140. Need to make ASCII art of some giant letters?
  141. <!-- exec -->
  142. $ figlet "R T F M"
  143. ____ _____ _____ __ __
  144. | _ \ |_ _| | ___| | \/ |
  145. | |_) | | | | |_ | |\/| |
  146. | _ < | | | _| | | | |
  147. |_| \_\ |_| |_| |_| |_|
  148. <!-- end -->
  149. cowsay
  150. ------
  151. How about ASCII art of a <del>cow</del> dragon saying something?
  152. <!-- exec -->
  153. $ cowsay -f dragon "RTFM, man"
  154. ___________
  155. < RTFM, man >
  156. -----------
  157. \ / \ //\
  158. \ |\___/| / \// \\
  159. /0 0 \__ / // | \ \
  160. / / \/_/ // | \ \
  161. @_^_@'/ \/_ // | \ \
  162. //_^_/ \/_ // | \ \
  163. ( //) | \/// | \ \
  164. ( / /) _|_ / ) // | \ _\
  165. ( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-.
  166. (( / / )) ,-{ _ `-.|.-~-. .~ `.
  167. (( // / )) '/\ / ~-. _ .-~ .-~^-. \
  168. (( /// )) `. { } / \ \
  169. (( / )) .----~-.\ \-' .~ \ `. \^-.
  170. ///.----..> \ _ -~ `. ^-` ^-_
  171. ///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
  172. /.-~
  173. <!-- end -->