shosei

Awk

Mar 28th, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 44.65 KB | None | 0 0
  1. .-----------------------------------------------------------------------.
  2. |                                                                       |
  3. |                              AWK Cheat Sheet                          |
  4. |                                                                       |
  5. '-----------------------------------------------------------------------'
  6. | Peteris Krumins ([email protected]), 2007.08.22                      |
  7. | http://www.catonmat.net  -  good coders code, great reuse             |
  8. '-----------------------------------------------------------------------'
  9.  
  10.  
  11.  ===================== Predefined Variable Summary =====================
  12.  
  13. .-------------+-----------------------------------.---------------------.
  14. |             |                                   |      Support:       |
  15. | Variable    | Description                       '-----.-------.-------'
  16. |             |                                   | AWK | NAWK  | GAWK  |
  17. '-------------+-----------------------------------+-----+-------+-------'
  18. | FS          | Input Field Separator, a space by |  +  |   +   |   +   |
  19. |             | default.                          |     |       |       |
  20. '-------------+-----------------------------------+-----+-------+-------'
  21. | OFS         | Output Field Separator, a space   |  +  |   +   |   +   |
  22. |             | by default.                       |     |       |       |
  23. '-------------+-----------------------------------+-----+-------+-------'
  24. | NF          | The Number of Fields in the       |  +  |   +   |   +   |
  25. |             | current input record.             |     |       |       |
  26. '-------------+-----------------------------------+-----+-------+-------'
  27. | NR          | The total Number of input Records |  +  |   +   |   +   |
  28. |             | seen so far.                      |     |       |       |
  29. '-------------+-----------------------------------+-----+-------+-------'
  30. | RS          | Record Separator, a newline by    |  +  |   +   |   +   |
  31. |             | default.                          |     |       |       |
  32. '-------------+-----------------------------------+-----+-------+-------'
  33. | ORS         | Output Record Separator, a        |  +  |   +   |   +   |
  34. |             | newline by default.               |     |       |       |
  35. '-------------+-----------------------------------+-----+-------+-------'
  36. | FILENAME    | The name of the current input     |     |       |       |
  37. |             | file. If no files are specified   |     |       |       |
  38. |             | on the command line, the value of |     |       |       |
  39. |             | FILENAME is "-". However,         |  +  |   +   |   +   |
  40. |             | FILENAME is undefined inside the  |     |       |       |
  41. |             | BEGIN block (unless set by        |     |       |       |
  42. |             | getline).                         |     |       |       |
  43. '-------------+-----------------------------------+-----+-------+-------'
  44. | ARGC        | The number of command line        |     |       |       |
  45. |             | arguments (does not include       |     |       |       |
  46. |             | options to gawk, or the program   |  -  |   +   |   +   |
  47. |             | source). Dynamically changing the |     |       |       |
  48. |             | contents of ARGV control the      |  -  |   +   |   +   |
  49. |             | files used for data.              |     |       |       |
  50. '-------------+-----------------------------------+-----+-------+-------'
  51. | ARGV        | Array of command line arguments.  |     |       |       |
  52. |             | The array is indexed from 0 to    |  -  |   +   |   +   |
  53. |             | ARGC - 1.                         |     |       |       |
  54. '-------------+-----------------------------------+-----+-------+-------'
  55. | ARGIND      | The index in ARGV of the current  |  -  |   -   |   +   |
  56. |             | file being processed.             |     |       |       |
  57. '-------------+-----------------------------------+-----+-------+-------'
  58. | BINMODE     | On non-POSIX systems, specifies   |     |       |       |
  59. |             | use of "binary" mode for all file |     |       |       |
  60. |             | I/O.Numeric values of 1, 2, or 3, |     |       |       |
  61. |             | specify that input files, output  |     |       |       |
  62. |             | files, or all files, respectively,|     |       |       |
  63. |             | should use binary I/O. String     |     |       |       |
  64. |             | values of  "r", or "w" specify    |  -  |   -   |   +   |
  65. |             | that input files, or output files,|     |       |       |
  66. |             | respectively, should use binary   |     |       |       |
  67. |             | I/O. String values of "rw" or     |     |       |       |
  68. |             |  "wr" specify that all files      |     |       |       |
  69. |             | should use binary I/O. Any other  |     |       |       |
  70. |             | string value is treated as "rw",  |     |       |       |
  71. |             | but generates a warning message.  |     |       |       |
  72. '-------------+-----------------------------------+-----+-------+-------'
  73. | CONVFMT     | The CONVFMT variable is used to   |     |       |       |
  74. |             | specify the format when           |  -  |   -   |   +   |
  75. |             | converting a number to a string.  |     |       |       |
  76. |             | Default: "%.6g"                   |     |       |       |
  77. '-------------+-----------------------------------+-----+-------+-------'
  78. | ENVIRON     | An array containing the values    |  -  |   -   |   +   |
  79. |             | of the current environment.       |     |       |       |
  80. '-------------+-----------------------------------+-----+-------+-------'
  81. | ERRNO       | If a system error occurs either   |     |       |       |
  82. |             | doing a redirection for getline,  |     |       |       |
  83. |             | during a read for getline, or     |     |       |       |
  84. |             | during a close(), then ERRNO will |  -  |   -   |   +   |
  85. |             | contain a string describing the   |     |       |       |
  86. |             | error. The value is subject to    |     |       |       |
  87. |             | translation in non-English locales.     |       |       |
  88. '-------------+-----------------------------------+-----+-------+-------'
  89. | FIELDWIDTHS | A white-space separated list of   |     |       |       |
  90. |             | fieldwidths. When set, gawk       |     |       |       |
  91. |             | parses the input into fields of   |  -  |   -   |   +   |
  92. |             | fixed width, instead of using the |     |       |       |
  93. |             | value of the FS variable as the   |     |       |       |
  94. |             | field separator.                  |     |       |       |
  95. '-------------+-----------------------------------+-----+-------+-------'
  96. | FNR         | Contains number of lines read,    |  -  |   +   |   +   |
  97. |             | but is reset for each file read.  |     |       |       |
  98. '-------------+-----------------------------------+-----+-------+-------'
  99. | IGNORECASE  | Controls the case-sensitivity of  |     |       |       |
  100. |             | all regular expression and string |     |       |       |
  101. |             | operations. If IGNORECASE has a   |     |       |       |
  102. |             | non-zero value, then string       |     |       |       |
  103. |             | comparisons and pattern matching  |     |       |       |
  104. |             | in rules, field splitting         |     |       |       |
  105. |             | with FS, record separating        |     |       |       |
  106. |             | with RS, regular expression       |     |       |       |
  107. |             | matching with ~ and !~, and the   |  -  |   -   |   +   |
  108. |             | gensub(), gsub(), index(),        |     |       |       |
  109. |             | match(), split(), and sub()       |     |       |       |
  110. |             | built-in functions all ignore     |     |       |       |
  111. |             | case when doing regular           |     |       |       |
  112. |             | expression operations.            |     |       |       |
  113. |             | NOTE: Array subscripting is not   |     |       |       |
  114. |             | affected. However, the asort()    |     |       |       |
  115. |             | and asorti() functions are        |     |       |       |
  116. |             | affected                          |     |       |       |
  117. '-------------+-----------------------------------+-----+-------+-------'
  118. | LINT        | Provides dynamic control of the   |     |       |       |
  119. |             | --lint option from within an AWK  |  -  |   -   |   +   |
  120. |             | program. When true, gawk prints   |     |       |       |
  121. |             | lint warnings.                    |     |       |       |
  122. '-------------+-----------------------------------+-----+-------+-------'
  123. | OFMT        | The default output format for     |  -  |   +   |   +   |
  124. |             | numbers. Default: "%.6g"          |     |       |       |
  125. '-------------+-----------------------------------+-----+-------+-------'
  126. | PROCINFO    | The elements of this array        |     |       |       |
  127. |             | provide access to information     |     |       |       |
  128. |             | about the running AWK program.    |     |       |       |
  129. |             | PROCINFO["egid"]:                 |     |       |       |
  130. |             | the value of the getegid(2)       |     |       |       |
  131. |             | system call.                      |     |       |       |
  132. |             | PROCINFO["euid"]:                 |     |       |       |
  133. |             | the value of the geteuid(2)       |     |       |       |
  134. |             | system call.                      |     |       |       |
  135. |             | PROCINFO["FS"]:                   |     |       |       |
  136. |             | "FS" if field splitting with FS   |     |       |       |
  137. |             | is in effect, or "FIELDWIDTHS"    |     |       |       |
  138. |             | if field splitting with           |     |       |       |
  139. |             | FIELDWIDTHS is in effect.         |     |       |       |
  140. |             | PROCINFO["gid"]:                  |  -  |   -   |   +   |
  141. |             | the value of the getgid(2) system |     |       |       |
  142. |             | call.                             |     |       |       |
  143. |             | PROCINFO["pgrpid"]:               |     |       |       |
  144. |             | the process group ID of the       |     |       |       |
  145. |             | current process.                  |     |       |       |
  146. |             | PROCINFO["pid"]:                  |     |       |       |
  147. |             | the process ID of the current     |     |       |       |
  148. |             | process.                          |     |       |       |
  149. |             | PROCINFO["ppid"]:                 |     |       |       |
  150. |             | the parent process ID of the      |     |       |       |
  151. |             | current process.                  |     |       |       |
  152. |             | PROCINFO["uid"]                   |     |       |       |
  153. |             | the value of the getuid(2) system |     |       |       |
  154. |             | call.                             |     |       |       |
  155. '-------------+-----------------------------------+-----+-------+-------'
  156. | RT          | The record terminator. Gawk sets  |     |       |       |
  157. |             | RT to the input text that matched |  -  |   -   |   +   |
  158. |             | the character or regular          |     |       |       |
  159. |             | expression specified by RS.       |     |       |       |
  160. '-------------+-----------------------------------+-----+-------+-------'
  161. | RSTART      | The index of the first character  |  -  |   +   |   +   |
  162. |             | matched by match(); 0 if no match.|     |       |       |
  163. '-------------+-----------------------------------+-----+-------+-------'
  164. | RLENGTH     | The length of the string matched  |  -  |   +   |   +   |
  165. |             | by match(); -1 if no match.       |     |       |       |
  166. '-------------+-----------------------------------+-----+-------+-------'
  167. | SUBSEP      | The character used to separate    |     |       |       |
  168. |             | multiple subscripts in array      |     |       |       |
  169. |             | elements.Default: "\034"          |  -  |   +   |   +   |
  170. |             | (non-printable character,         |     |       |       |
  171. |             | dec: 28, hex: 1C)                 |     |       |       |
  172. '-------------+-----------------------------------+-----+-------+-------'
  173. | TEXTDOMAIN  | The text domain of the AWK        |     |       |       |
  174. |             | program; used to find the         |  -  |   -   |   +   |
  175. |             | localized translations for the    |     |       |       |
  176. |             | program's strings.                |     |       |       |
  177. '-------------'-----------------------------------'-----'-------'-------'
  178.  
  179.  
  180.  ============================ I/O Statements ===========================
  181.  
  182. .---------------------.-------------------------------------------------.
  183. |                     |                                                 |
  184. | Statement           | Description                                     |
  185. |                     |                                                 |
  186. '---------------------+-------------------------------------------------'
  187. | close(file [, how]) | Close file, pipe or co-process. The optional    |
  188. |                     | how should only be used when closing one end of |
  189. |                     | a two-way pipe to a co-process. It must be a    |
  190. |                     | string value, either "to" or "from".            |
  191. '---------------------+-------------------------------------------------'
  192. | getline             | Set $0 from next input record; set NF, NR, FNR. |
  193. |                     | Returns 0 on EOF and 1 on an error. Upon an    |
  194. |                     | error, ERRNO contains a string describing the   |
  195. |                     | problem.                                        |
  196. '---------------------+-------------------------------------------------'
  197. | getline <file       | Set $0 from next record of file; set NF.        |
  198. '---------------------+-------------------------------------------------'
  199. | getline var         | Set var from next input record; set NR, FNR.    |
  200. '---------------------+-------------------------------------------------'
  201. | getline var <file   | Set var from next record of file.               |
  202. '---------------------+-------------------------------------------------'
  203. | command |           | Run command piping the output either into $0 or |
  204. |   getline [var]     | var, as above. If using a pipe or co-process    |
  205. |                     | to getline, or from print or printf within a    |
  206. |                     | loop, you must use close() to create new        |
  207. |                     | instances                                       |
  208. '---------------------+-------------------------------------------------'
  209. | command |&          | Run command as a co-process piping the output   |
  210. |   getline [var]     | either into $0 or var, as above.  Co-processes  |
  211. |                     | are a gawk extension.                           |
  212. '---------------------+-------------------------------------------------'
  213. | next                | Stop processing the current input record.       |
  214. |                     | The next input record is read and processing    |
  215. |                     | starts over with the first pattern in the AWK   |
  216. |                     | program. If the end of the input data is        |
  217. |                     | reached, the END block(s), if any, are executed.|
  218. '---------------------+-------------------------------------------------'
  219. | nextfile            | Stop processing the current input file. The     |
  220. |                     | next input record read comes from the next      |
  221. |                     | input file. FILENAME and ARGIND are updated,    |
  222. |                     | FNR is reset to 1, and processing starts over   |
  223. |                     | with the first pattern in the AWK program. If   |
  224. |                     | the end of the input data is reached, the END   |
  225. |                     | block(s), are executed.                         |
  226. '---------------------+-------------------------------------------------'
  227. | print               | Prints the current record. The output record is |
  228. |                     | terminated with the value of the ORS variable.  |
  229. '---------------------+-------------------------------------------------'
  230. | print expr-list     | Prints expressions. Each expression is          |
  231. |                     | separated by the value of the OFS variable.     |
  232. |                     | The output record is terminated with the value  |
  233. |                     | of the ORS variable.                            |
  234. '---------------------+-------------------------------------------------'
  235. | print expr-list     | Prints expressions on file. Each expression is  |
  236. |   >file             | separated by the value of the OFS variable. The |
  237. |                     | output record is terminated with the value of   |
  238. |                     | the ORS variable.                               |
  239. '---------------------+-------------------------------------------------'
  240. | printf fmt,         | Format and print.                               |
  241. |   expr-list         |                                                 |
  242. '---------------------+-------------------------------------------------'
  243. | printf fmt,         | Format and print on file.                       |
  244. |   expr-list >file   |                                                 |
  245. '---------------------+-------------------------------------------------'
  246. | system(cmd-line)    | Execute the command cmd-line, and return the    |
  247. |                     | exit status.                                    |
  248. '---------------------+-------------------------------------------------'
  249. | fflush([file])      | Flush any buffers associated with the open      |
  250. |                     | output file or pipe file. If file is missing,   |
  251. |                     | then stdout is flushed. If file is the null     |
  252. |                     | string, then all open output files and pipes    |
  253. |                     | have their buffers flushed.                     |
  254. '---------------------+-------------------------------------------------'
  255. | print ... >> file   | Appends output to the file.                     |
  256. '---------------------+-------------------------------------------------'
  257. | print ... | command | Writes on a pipe.                               |
  258. '---------------------+-------------------------------------------------'
  259. | print ... |&        | Sends data to a co-process.                     |
  260. |   command           |                                                 |
  261. '---------------------'-------------------------------------------------'
  262.  
  263.  
  264.  =========================== Numeric Functions =========================
  265.  
  266. .---------------------.-------------------------------------------------.
  267. |                     |                                                 |
  268. | Function            | Description                                     |
  269. |                     |                                                 |
  270. '---------------------+-------------------------------------------------'
  271. | atan2(y, x)         | Returns the arctangent of y/x in radians.       |
  272. '---------------------+-------------------------------------------------'
  273. | cos(expr)           | Returns the cosine of expr, which is in radians.|
  274. '---------------------+-------------------------------------------------'
  275. | exp(expr)           | The exponential function.                       |
  276. '---------------------+-------------------------------------------------'
  277. | int(expr)           | Truncates to integer.                           |
  278. '---------------------+-------------------------------------------------'
  279. | log(expr)           | The natural logarithm function.                 |
  280. '---------------------+-------------------------------------------------'
  281. | rand()              | Returns a random number N, between 0 and 1,     |
  282. |                     | such that 0 <= N < 1.                           |
  283. '---------------------+-------------------------------------------------'
  284. | sin(expr)           | Returns the sine of expr, which is in radians.  |
  285. '---------------------+-------------------------------------------------'
  286. | sqrt(expr)          | The square root function.                       |
  287. '---------------------+-------------------------------------------------'
  288. | srand([expr])       | Uses expr as a new seed for the random number   |
  289. |                     | generator. If no expr is provided, the time of  |
  290. |                     | day is used. The return value is the previous   |
  291. |                     | seed for the random number generator.           |
  292. '---------------------'-------------------------------------------------'
  293.  
  294.  
  295.  ====================== Bit Manipulation Functions =====================
  296.  
  297. .---------------------.-------------------------------------------------.
  298. |                     |                                                 |
  299. | Function            | Description                                     |
  300. |                     |                                                 |
  301. '---------------------+-------------------------------------------------'
  302. | and(v1, v2)         | Return the bitwise AND of the values provided   |
  303. |                     | by v1 and v2.                                   |
  304. '---------------------+-------------------------------------------------'
  305. | compl(val)          | Return the bitwise complement of val.           |
  306. '---------------------+-------------------------------------------------'
  307. | lshift(val, count)  | Return the value of val, shifted left by        |
  308. |                     | count bits.                                     |
  309. '---------------------+-------------------------------------------------'
  310. | or(v1, v2)          | Return the bitwise OR of the values provided by |
  311. |                     | v1 and v2.                                      |
  312. '---------------------+-------------------------------------------------'
  313. | rshift(val, count)  | Return the value of val, shifted right by       |
  314. |                     | count bits.                                     |
  315. '---------------------+-------------------------------------------------'
  316. | xor(v1, v2)         | Return the bitwise XOR of the values provided   |
  317. |                     | by v1 and v2.                                   |
  318. '---------------------'-------------------------------------------------'
  319.  
  320.  
  321.  =========================== String Functions ==========================
  322.  
  323. .---------------------.-------------------------------------------------.
  324. |                     |                                                 |
  325. | Function            | Description                                     |
  326. |                     |                                                 |
  327. '---------------------+-------------------------------------------------'
  328. | asort(s [, d])      | Returns the number of elements in the source    |
  329. |                     | array s.  The contents of s are sorted using    |
  330. |                     | gawk's normal rules for comparing values, and   |
  331. |                     | the indexes of the sorted values of s are       |
  332. |                     | replaced with sequential integers starting with |
  333. |                     | 1. If the optional destination array d is       |
  334. |                     | specified, then s is first duplicated into d,   |
  335. |                     | and then d is sorted, leaving the indexes of    |
  336. |                     | the source array s unchanged.                   |
  337. '---------------------+-------------------------------------------------'
  338. | asorti(s [, d])     | Returns the number of elements in the source    |
  339. |                     | array s. The behavior is the same as that of    |
  340. |                     | asort(),  except that the array indices are     |
  341. |                     | used for sorting, not the array values. When    |
  342. |                     | done, the array is indexed numerically, and the |
  343. |                     | values are those of the original indices. The   |
  344. |                     | original values are lost; thus provide a second |
  345. |                     | array if you wish to preserve the original.     |
  346. '---------------------+-------------------------------------------------'
  347. | gensub(r, s,        | Search the target string t for matches of the   |
  348. |   h [, t])          | regular expression r.  If h is a string         |
  349. |                     | beginning with g or G, then replace all matches |
  350. |                     | of r with s. Otherwise, h is a number           |
  351. |                     | indicating which match of r to replace. If t is |
  352. |                     | not supplied, $0 is used instead. Within the    |
  353. |                     | replacement text s, the sequence \n, where n is |
  354. |                     | a digit from 1 to 9, may be used to indicate    |
  355. |                     | just the text that matched the n'th             |
  356. |                     | parenthesized subexpression. The sequence \0    |
  357. |                     | represents the entire matched text, as does the |
  358. |                     | character &. Unlike sub() and gsub(), the       |
  359. |                     | modified string is returned as the result of    |
  360. |                     | the function, and the original target string    |
  361. |                     | is not changed.                                 |
  362. '---------------------+-------------------------------------------------'
  363. | gsub(r, s [, t])    | For each substring matching the regular         |
  364. |                     | expression r in the string t, substitute the    |
  365. |                     | string s, and return the number of              |
  366. |                     | substitutions.  If t is not supplied, use $0.   |
  367. |                     | An & in the replacement text is replaced with   |
  368. |                     | the text that was actually matched. Use \& to   |
  369. |                     | get a literal &.  (This must be                 |
  370. |                     | typed as  "\\&")                                |
  371. '---------------------+-------------------------------------------------'
  372. | index(s, t)         | Returns the index of the string t in the        |
  373. |                     | string s, or 0 if t is not present. (This       |
  374. |                     | implies that characterindices start at one.)    |
  375. '---------------------+-------------------------------------------------'
  376. | length([s])         | Returns the length of the string s, or the      |
  377. |                     | length of $0 if s is not supplied.              |
  378. '---------------------+-------------------------------------------------'
  379. | match(s, r [, a])   | Returns the position in s where the regular     |
  380. |                     | expression r occurs, or 0 if r is not present,  |
  381. |                     | and sets the values of RSTART and RLENGTH.      |
  382. |                     | Note that the argument order is the same as for |
  383. |                     | the ~ operator:  str  ~  re. If array a is      |
  384. |                     | provided, a is cleared and then elements 1      |
  385. |                     | through n are filled with the portions of s     |
  386. |                     | that match the corresponding parenthesized      |
  387. |                     | subexpression in r.  The 0'th element of a      |
  388. |                     | contains the portion of s matched by the entire |
  389. |                     | regular expression r. Subscripts a[n, "start"], |
  390. |                     | and a[n, "length"] provide the starting index   |
  391. |                     | in the string and length respectively, of each  |
  392. |                     | matching substring.                             |
  393. '---------------------+-------------------------------------------------'
  394. | split(s, a [, r])   | Splits the string s into the array a on the     |
  395. |                     | regular expression r, and returns the number of |
  396. |                     | fields. If r is omitted, FS is used instead.    |
  397. |                     | The array a is cleared first. Splitting behaves |
  398. |                     | identically to field splitting.                 |
  399. '---------------------+-------------------------------------------------'
  400. | sprintf(fmt,        | Prints expr-list according to fmt, and returns  |
  401. |   expr-list)        | the resulting string.                           |
  402. '---------------------+-------------------------------------------------'
  403. | strtonum(str)       | Examines str, and returns its numeric value.    |
  404. |                     | If str begins with a leading 0, strtonum()      |
  405. |                     | assumes that  str is an octal number. If str    |
  406. |                     | begins with a leading 0x or 0X, strtonum()      |
  407. |                     | assumes that str is a hexadecimal number.       |
  408. '---------------------+-------------------------------------------------'
  409. | sub(r, s [, t])     | Just like gsub(), but only the first matching   |
  410. |                     | substring is replaced.                          |
  411. '---------------------+-------------------------------------------------'
  412. | substr(s, i [, n])  | Returns the at most n-character substring of s  |
  413. |                     | starting at i.  If n is omitted, the rest of s  |
  414. |                     | is used.                                        |
  415. '---------------------+-------------------------------------------------'
  416. | tolower(str)        | Returns a copy of the string str, with all the  |
  417. |                     | upper-case characters in str translated to      |
  418. |                     | their corresponding lower-case counterparts.    |
  419. |                     | Non-alphabetic characters are left unchanged.   |
  420. '---------------------+-------------------------------------------------'
  421. | toupper(str)        | Returns a copy of the string str, with all the  |
  422. |                     | lower-case characters in str translated to      |
  423. |                     | their corresponding upper-case counterparts.    |
  424. |                     | Non-alphabetic characters are left unchanged.   |
  425. '---------------------'-------------------------------------------------'
  426.  
  427.  
  428.  ============================ Time Functions ===========================
  429.  
  430. .---------------------.-------------------------------------------------.
  431. |                     |                                                 |
  432. | Function            | Description                                     |
  433. |                     |                                                 |
  434. '---------------------+-------------------------------------------------'
  435. | mktime(datespec)    | Turns datespec into a time stamp of the same    |
  436. |                     | form as returned by systime(). The datespec is  |
  437. |                     | a string of the form YYYY MM DD HH MM SS[ DST]. |
  438. |                     | The contents of the string are six or seven     |
  439. |                     | numbers representing respectively the full year |
  440. |                     | including century, the month from 1 to 12, the  |
  441. |                     | day of the month from 1 to 31, the hour of the  |
  442. |                     | day from 0 to 23, the minute from 0 to 59, and  |
  443. |                     | the second from 0 to 60, and an optional        |
  444. |                     | daylight saving flag. The values of these       |
  445. |                     | numbers need not be within the ranges           |
  446. |                     | specified; for example, an hour of -1 means 1   |
  447. |                     | hour before midnight. The origin-zero Gregorian |
  448. |                     | calendar is assumed, with year 0 preceding year |
  449. |                     | 1 and year -1 preceding year 0. The time is     |
  450. |                     | assumed to be in the local timezone. If the     |
  451. |                     | daylight saving flag is positive, the time is   |
  452. |                     | assumed to be daylight saving time; if zero,    |
  453. |                     | the time is assumed to be standard time; and if |
  454. |                     | negative (the default), mktime() attempts to    |
  455. |                     | determine whether daylight saving time is in    |
  456. |                     | effect for the specified time. If datespec does |
  457. |                     | not contain enough elements or if the resulting |
  458. |                     | time is out of range, mktime() returns -1.      |
  459. '---------------------+-------------------------------------------------'
  460. | strftime([format    | Formats timestamp according to the              |
  461. |   [, timestamp]])   | specification in format. The timestamp should   |
  462. |                     | be of the same form as returned by systime().   |
  463. |                     | If timestamp is missing, the current time of    |
  464. |                     | day is used.If format is missing, a default     |
  465. |                     | format equivalent to the output of date(1) is   |
  466. |                     | used.  See the specification for the strftime() |
  467. |                     | function in ANSI C for the format conversions   |
  468. |                     | that are guaranteed to be available. A          |
  469. |                     | public-domain version of strftime(3) and a man  |
  470. |                     | page for it come with gawk; if that version was |
  471. |                     | used to build gawk, then all of the conversions |
  472. |                     | described in that man page are available to     |
  473. |                     | gawk.                                           |
  474. '---------------------+-------------------------------------------------'
  475. | systime()           | Returns the current time of day as the number   |
  476. |                     | of seconds since the Epoch (1970-01-01 00:00:00 |
  477. |                     | UTC on POSIX systems).                          |
  478. '---------------------'-------------------------------------------------'
  479.  
  480.  
  481.  =============== Internationalization (I18N)  Functions ================
  482.  
  483. .---------------------.-------------------------------------------------.
  484. |                     |                                                 |
  485. | Function            |                                                 |
  486. |                     |                                                 |
  487. | Description         |                                                 |
  488. |                     |                                                 |
  489. '---------------------+-------------------------------------------------'
  490. | bindtextdomain(directory [, domain])                                  |
  491. |                                                                       |
  492. | Specifies the directory where gawk looks for the .mo files. It        |
  493. | returns the directory where domain is ``bound.'' The default domain   |
  494. | is the value of TEXTDOMAIN.  If directory is the null string (""),    |
  495. | then bindtextdomain() returns the current binding for the given domain|
  496. '---------------------+-------------------------------------------------'
  497. | dcgettext(string [, domain [, category]])                             |
  498. |                                                                       |
  499. | Returns the translation of string in text domain domain for locale    |
  500. | category category. The default value for domain is the current value  |
  501. | of TEXTDOMAIN. The default value for category is "LC_MESSAGES". If    |
  502. | you supply a value for category, it must be a string equal to one of  |
  503. | the known locale categories. You must also supply a text domain. Use  |
  504. | TEXTDOMAIN if you want to use the current domain.                     |
  505. '---------------------+-------------------------------------------------'
  506. | dcngettext(string1 , string2 , number [, domain [, category]])        |
  507. |                                                                       |
  508. | Returns the plural form used for number of the translation of string1 |
  509. | and string2 in text domain domain for locale category category. The   |
  510. | default value for domain is the current value of TEXTDOMAIN. The      |
  511. | default value for category is "LC_MESSAGES". If you supply a value    |
  512. | for category, it must be a string equal to one of the known locale    |
  513. | categories. You must also supply a text domain. Use TEXTDOMAIN if     |
  514. | you want to use the current domain.                                   |
  515. '---------------------'-------------------------------------------------'
  516.  
  517.  
  518.  
  519.  
  520.  =============== GNU AWK's Command Line Argument Summary ===============
  521.  
  522. .-------------------------.---------------------------------------------.
  523. |                         |                                             |
  524. | Argument                | Description                                 |
  525. |                         |                                             |
  526. '-------------------------+---------------------------------------------'
  527. | -F fs                   | Use fs for the input field separator        |
  528. | --field-sepearator fs   | (the value of the FS predefined variable).  |
  529. '-------------------------+---------------------------------------------'
  530. | -v var=val              | Assign the value val to the variable var,   |
  531. | --assign var=val        | before execution of the program begins.     |
  532. |                         | Such variable values are available to the   |
  533. |                         | BEGIN block of an AWK program.              |
  534. '-------------------------+---------------------------------------------'
  535. | -f program-file         | Read the AWK program source from the file   |
  536. | --file program-file     | program-file, instead of from the first     |
  537. |                         | command line argument. Multiple -f          |
  538. |                         | (or --file) options may be used.            |
  539. '-------------------------+---------------------------------------------'
  540. | -mf NNN                 | Set various memory limits to the value NNN. |
  541. | -mr NNN                 | The f flag sets the maximum number of       |
  542. |                         | fields, and the r flag sets the maximum     |
  543. |                         | record size. (Ignored by gawk, since gawk   |
  544. |                         | has no pre-defined limits)                  |
  545. '-------------------------+---------------------------------------------'
  546. | -W compat               | Run in compatibility mode. In compatibility |
  547. | -W traditional          | mode, gawk behaves identically to UNIX awk; |
  548. | --compat--traditional   | none of the GNU-specific extensions are     |
  549. |                         | recognized.                                 |
  550. '-------------------------+---------------------------------------------'
  551. | -W copyleft             | Print the short version of the GNU copyright|
  552. | -W copyright            | information message on the standard output  |
  553. | --copyleft              | and exit successfully.                      |
  554. | --copyright             |                                             |
  555. '-------------------------+---------------------------------------------'
  556. | -W dump-variables[=file]| Print a sorted list of global variables,    |
  557. | --dump-variables[=file] | their types and final values to file. If no |
  558. |                         | file is provided, gawk uses a file named    |
  559. |                         | awkvars.out in the current directory.       |
  560. '-------------------------+---------------------------------------------'
  561. | -W help                 | Print a relatively short summary of the     |
  562. | -W usage                | available options on the standard output.   |
  563. | --help                  |                                             |
  564. | --usage                 |                                             |
  565. '-------------------------+---------------------------------------------'
  566. |-W lint[=value]          | Provide warnings about constructs that      |
  567. |--lint[=value]           | are dubious or non-portable to other AWK    |
  568. |                         | impls. With argument fatal, lint warnings  |
  569. |                         | become fatal errors. With an optional       |
  570. |                         | argument of invalid, only warnings about    |
  571. |                         | things that are actually invalid are        |
  572. |                         | issued. (This is not fully implemented yet.)|
  573. '-------------------------+---------------------------------------------'
  574. | -W lint-old--lint-old   | Provide warnings about constructs that are  |
  575. |                         | not portable to the original version of     |
  576. |                         | Unix awk.                                   |
  577. '-------------------------+---------------------------------------------'
  578. | -W gen-po--gen-po       | Scan and parse the AWK program, and         |
  579. |                         | generate a GNU .po format file on standard  |
  580. |                         | output with entries for all localizable     |
  581. |                         | strings in the program. The program itself  |
  582. |                         | is not executed.                            |
  583. '-------------------------+---------------------------------------------'
  584. | -W non-decimal-data     | Recognize octal and hexadecimal values in   |
  585. | --non-decimal-data      | input data.                                 |
  586. '-------------------------+---------------------------------------------'
  587. | -W posix--posix         | This turns on compatibility mode, with the  |
  588. |                         | following additional restrictions:          |
  589. |                         | o  \x escape sequences are not recognized.  |
  590. |                         | o  Only space and tab act as field          |
  591. |                         |    separators when FS is set to a single    |
  592. |                         |    space, new-line does not.                |
  593. |                         | o  You cannot continue lines after ? and :. |
  594. |                         | o  The synonym func for the keyword function|
  595. |                         |    is not recognized.                       |
  596. |                         | o  The operators ** and **= cannot be used  |
  597. |                         |    in place of ^ and ^=.  The fflush()     |
  598. |                         |    function is not available.               |
  599. '-------------------------+---------------------------------------------'
  600. | -W profile[=prof_file]  | Send profiling data to prof_file.           |
  601. | --profile[=prof_file]   | The default is awkprof.out. When run with   |
  602. |                         | gawk, the profile is just a "pretty         |
  603. |                         | printed" version of the program. When run   |
  604. |                         | with pgawk, the profile contains execution  |
  605. |                         | counts of each statement in the program     |
  606. |                         | in the left margin and function call counts |
  607. |                         | for each user-defined function.             |
  608. '-------------------------+---------------------------------------------'
  609. | -W re-interval          | Enable the use of interval expressions in   |
  610. | --re-interval           | regular expression matching. Interval       |
  611. |                         | expressions were not traditionally          |
  612. |                         | available in the AWK language.              |
  613. '-------------------------+---------------------------------------------'
  614. | -W source program-text  | Use program-text as AWK program source      |
  615. | --source program-text   | code. This option allows the easy           |
  616. |                         | intermixing of library functions (used via  |
  617. |                         | the -f and --file options) with source code |
  618. |                         | entered on the command line.                |
  619. '-------------------------+---------------------------------------------'
  620. | -W version              | Print version information for this          |
  621. | --version               | particular copy of gawk on the standard     |
  622. |                         | output.                                     |
  623. '-------------------------+---------------------------------------------'
  624. | --                      | Signal the end of options. This is useful   |
  625. |                         | to allow further arguments to the AWK       |
  626. |                         | program itself to start with a "-". This    |
  627. |                         | is mainly for consistency with the argument |
  628. |                         | parsing convention used by most other POSIX |
  629. |                         | programs.                                   |
  630. '-------------------------'---------------------------------------------'
  631.  
  632.  =======================================================================
  633.  
  634. .-----------------------------------------------------------------------.
  635. | Peteris Krumins ([email protected]), 2007.08.22                      |
  636. | http://www.catonmat.net  -  good coders code, great reuse             |
  637. '-----------------------------------------------------------------------'
Advertisement
Add Comment
Please, Sign In to add comment