1 #+OPTIONS: H:3 num:nil toc:2 \n:nil @:t ::t |:t ^:{} -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
2 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks
3 #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n)
5 #+TITLE: AWK Source Code Blocks in Org Mode
6 #+AUTHOR: Thomas S. Dye
7 #+EMAIL: tsd[at]tsdye[dot]com
9 #+STYLE: <style type="text/css">#outline-container-introduction{ clear:both; }</style>
10 #+LINK_UP: ../languages.html
11 #+LINK_HOME: http://orgmode.org/worg/
12 #+EXPORT_EXCLUDE_TAGS: noexport
16 <div id="subtitle" style="float: center; text-align: center;">
18 Org Mode support for <a href="http://c2.com/cgi/wiki?AwkLanguage">AWK</a>
23 * Template Checklist [12/12] :noexport:
25 - [X] Indicate #+AUTHOR:
27 - [X] Revise banner source block [3/3]
28 - [X] Add link to a useful language web site
29 - [X] Replace "Language" with language name
30 - [X] Find a suitable graphic and use it to link to the language
32 - [X] Write an [[Introduction]]
33 - [X] Describe [[Requirements%20and%20Setup][Requirements and Setup]]
34 - [X] Replace "Language" with language name in [[Org%20Mode%20Features%20for%20Language%20Source%20Code%20Blocks][Org Mode Features for Language Source Code Blocks]]
35 - [X] Describe [[Header%20Arguments][Header Arguments]]
36 - [X] Describe support for [[Sessions]]
37 - [X] Describe [[Result%20Types][Result Types]]
38 - [X] Describe [[Other]] differences from supported languages
39 - [X] Provide brief [[Examples%20of%20Use][Examples of Use]]
41 =AWK= is a task-specific language optimized for regular expression
42 record data manipulation.
44 * Requirements and Setup
45 There are many [[http://www.faqs.org/faqs/computer-lang/awk/faq/][well-maintained AWK compatible languages]]. The
46 variable =org-babel-awk-command= holds the name of =AWK= executable.
49 To configure =AWK= source code blocks in Org mode, add the appropriate
50 dotted pair to =org-babel-load-languages=
52 #+begin_src emacs-lisp :exports code
53 (org-babel-do-load-languages
54 'org-babel-load-languages
58 * Org Mode Features for AWK Source Code Blocks
60 There are three =AWK=-specific header arguments.
61 - =:cmd-line= :: takes command line arguments to pass to the =AWK= executable
62 - =:in-file= :: takes a path to a file of data to be processed by =AWK=
63 - =:stdin= :: takes an Org-mode data or code block reference, the
64 value of which will be passed to the =AWK= process
67 =AWK= does not support sessions.
71 Two examples from [[http://www.gnu.org/software/gawk/manual/gawk.html#Getting-Started][GNU Awk User's Guide]] show simple uses of =AWK=.
73 Given the table =bbs-list=
76 | aardvark | 555-5553 | 1200/300 | B |
77 | alpo-net | 555-3412 | 2400/1200/300 | A |
78 | barfly | 555-7685 | 1200/300 | A |
79 | bites | 555-1675 | 2400/1200/300 | A |
80 | camelot | 555-0542 | 300 | C |
81 | core | 555-2912 | 1200/300 | C |
82 | fooey | 555-1234 | 2400/1200/300 | B |
83 | foot | 555-6699 | 1200/300 | B |
84 | macfoo | 555-6480 | 1200/300 | A |
85 | sdace | 555-3430 | 2400/1200/300 | A |
86 | sabafoo | 555-2127 | 1200/300 | C |
88 this =AWK= source code block
90 ,#+begin_src awk :stdin bbs-list
95 returns a subset of the original table
97 #+begin_src awk :stdin bbs-list :exports results
102 | fooey | 555-1234 | 2400/1200/300 | B |
103 | foot | 555-6699 | 1200/300 | B |
104 | macfoo | 555-6480 | 1200/300 | A |
105 | sabafoo | 555-2127 | 1200/300 | C |
108 Given the table =inventory-shipped=
110 #+name: inventory-shipped
111 | Jan | 13 | 25 | 15 | 115 |
112 | Feb | 15 | 32 | 24 | 226 |
113 | Mar | 15 | 24 | 34 | 228 |
114 | Apr | 31 | 52 | 63 | 420 |
115 | May | 16 | 34 | 29 | 208 |
116 | Jun | 31 | 42 | 75 | 492 |
117 | Jul | 24 | 34 | 67 | 436 |
118 | Aug | 15 | 34 | 47 | 316 |
119 | Sep | 13 | 55 | 37 | 277 |
120 | Oct | 29 | 54 | 68 | 525 |
121 | Nov | 20 | 87 | 82 | 577 |
122 | Dec | 17 | 35 | 61 | 401 |
124 | Jan | 21 | 36 | 64 | 620 |
125 | Feb | 26 | 58 | 80 | 652 |
126 | Mar | 24 | 75 | 70 | 495 |
127 | Apr | 21 | 70 | 74 | 514 |
129 this bit of =AWK= code
132 ,#+begin_src awk :stdin inventory-shipped :exports results
137 returns this subset of the table
139 #+begin_src awk :stdin inventory-shipped :exports results
144 | Jan | 13 | 25 | 15 | 115 |
145 | Jun | 31 | 42 | 75 | 492 |
146 | Jul | 24 | 34 | 67 | 436 |
147 | Jan | 21 | 36 | 64 | 620 |