home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume22 / gawk2.11 / part05 < prev    next >
SHell self-extracting ARchive  |  1990-06-07  |  54.0 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: SHell self-extracting ARchive (archive/shar).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Newsgroup Content (archive/news) magic Supported
100% dexvert SHell self-extracting ARchive (archive/shar) magic Supported
100% dexvert Internet Message Format (text/imf) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file news or mail, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/329 Shell Archive Format default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime message/rfc822 default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 53 75 62 6a 65 63 74 3a | 20 20 76 32 32 69 30 39 |Subject:| v22i09|
|00000010| 31 3a 20 20 47 4e 55 20 | 41 57 4b 2c 20 76 65 72 |1: GNU |AWK, ver|
|00000020| 73 69 6f 6e 20 32 2e 31 | 31 2c 20 50 61 72 74 30 |sion 2.1|1, Part0|
|00000030| 35 2f 31 36 0a 4e 65 77 | 73 67 72 6f 75 70 73 3a |5/16.New|sgroups:|
|00000040| 20 63 6f 6d 70 2e 73 6f | 75 72 63 65 73 2e 75 6e | comp.so|urces.un|
|00000050| 69 78 0a 41 70 70 72 6f | 76 65 64 3a 20 72 73 61 |ix.Appro|ved: rsa|
|00000060| 6c 7a 40 75 75 6e 65 74 | 2e 55 55 2e 4e 45 54 0a |lz@uunet|.UU.NET.|
|00000070| 58 2d 43 68 65 63 6b 73 | 75 6d 2d 53 6e 65 66 72 |X-Checks|um-Snefr|
|00000080| 75 3a 20 33 33 66 39 34 | 65 31 35 20 36 61 38 38 |u: 33f94|e15 6a88|
|00000090| 35 34 61 37 20 33 37 63 | 30 33 34 62 36 20 35 39 |54a7 37c|034b6 59|
|000000a0| 38 63 66 39 38 35 0a 0a | 53 75 62 6d 69 74 74 65 |8cf985..|Submitte|
|000000b0| 64 2d 62 79 3a 20 22 41 | 72 6e 6f 6c 64 20 44 2e |d-by: "A|rnold D.|
|000000c0| 20 52 6f 62 62 69 6e 73 | 22 20 3c 61 72 6e 6f 6c | Robbins|" <arnol|
|000000d0| 64 40 75 6e 69 78 2e 63 | 63 2e 65 6d 6f 72 79 2e |d@unix.c|c.emory.|
|000000e0| 65 64 75 3e 0a 50 6f 73 | 74 69 6e 67 2d 6e 75 6d |edu>.Pos|ting-num|
|000000f0| 62 65 72 3a 20 56 6f 6c | 75 6d 65 20 32 32 2c 20 |ber: Vol|ume 22, |
|00000100| 49 73 73 75 65 20 39 31 | 0a 41 72 63 68 69 76 65 |Issue 91|.Archive|
|00000110| 2d 6e 61 6d 65 3a 20 67 | 61 77 6b 32 2e 31 31 2f |-name: g|awk2.11/|
|00000120| 70 61 72 74 30 35 0a 0a | 23 21 20 2f 62 69 6e 2f |part05..|#! /bin/|
|00000130| 73 68 0a 23 20 54 68 69 | 73 20 69 73 20 61 20 73 |sh.# Thi|s is a s|
|00000140| 68 65 6c 6c 20 61 72 63 | 68 69 76 65 2e 20 20 52 |hell arc|hive. R|
|00000150| 65 6d 6f 76 65 20 61 6e | 79 74 68 69 6e 67 20 62 |emove an|ything b|
|00000160| 65 66 6f 72 65 20 74 68 | 69 73 20 6c 69 6e 65 2c |efore th|is line,|
|00000170| 20 74 68 65 6e 20 66 65 | 65 64 20 69 74 0a 23 20 | then fe|ed it.# |
|00000180| 69 6e 74 6f 20 61 20 73 | 68 65 6c 6c 20 76 69 61 |into a s|hell via|
|00000190| 20 22 73 68 20 66 69 6c | 65 22 20 6f 72 20 73 69 | "sh fil|e" or si|
|000001a0| 6d 69 6c 61 72 2e 20 20 | 54 6f 20 6f 76 65 72 77 |milar. |To overw|
|000001b0| 72 69 74 65 20 65 78 69 | 73 74 69 6e 67 20 66 69 |rite exi|sting fi|
|000001c0| 6c 65 73 2c 0a 23 20 74 | 79 70 65 20 22 73 68 20 |les,.# t|ype "sh |
|000001d0| 66 69 6c 65 20 2d 63 22 | 2e 0a 23 20 54 68 65 20 |file -c"|..# The |
|000001e0| 74 6f 6f 6c 20 74 68 61 | 74 20 67 65 6e 65 72 61 |tool tha|t genera|
|000001f0| 74 65 64 20 74 68 69 73 | 20 61 70 70 65 61 72 65 |ted this| appeare|
|00000200| 64 20 69 6e 20 74 68 65 | 20 63 6f 6d 70 2e 73 6f |d in the| comp.so|
|00000210| 75 72 63 65 73 2e 75 6e | 69 78 20 6e 65 77 73 67 |urces.un|ix newsg|
|00000220| 72 6f 75 70 3b 0a 23 20 | 73 65 6e 64 20 6d 61 69 |roup;.# |send mai|
|00000230| 6c 20 74 6f 20 63 6f 6d | 70 2d 73 6f 75 72 63 65 |l to com|p-source|
|00000240| 73 2d 75 6e 69 78 40 75 | 75 6e 65 74 2e 75 75 2e |s-unix@u|unet.uu.|
|00000250| 6e 65 74 20 69 66 20 79 | 6f 75 20 77 61 6e 74 20 |net if y|ou want |
|00000260| 74 68 61 74 20 74 6f 6f | 6c 2e 0a 23 20 43 6f 6e |that too|l..# Con|
|00000270| 74 65 6e 74 73 3a 20 20 | 2e 2f 67 61 77 6b 2e 74 |tents: |./gawk.t|
|00000280| 65 78 69 6e 66 6f 2e 30 | 32 20 2e 2f 72 65 67 65 |exinfo.0|2 ./rege|
|00000290| 78 2e 63 2e 30 32 0a 23 | 20 57 72 61 70 70 65 64 |x.c.02.#| Wrapped|
|000002a0| 20 62 79 20 72 73 61 6c | 7a 40 6c 69 74 63 68 69 | by rsal|z@litchi|
|000002b0| 2e 62 62 6e 2e 63 6f 6d | 20 6f 6e 20 57 65 64 20 |.bbn.com| on Wed |
|000002c0| 4a 75 6e 20 20 36 20 31 | 32 3a 32 34 3a 34 39 20 |Jun 6 1|2:24:49 |
|000002d0| 31 39 39 30 0a 50 41 54 | 48 3d 2f 62 69 6e 3a 2f |1990.PAT|H=/bin:/|
|000002e0| 75 73 72 2f 62 69 6e 3a | 2f 75 73 72 2f 75 63 62 |usr/bin:|/usr/ucb|
|000002f0| 20 3b 20 65 78 70 6f 72 | 74 20 50 41 54 48 0a 65 | ; expor|t PATH.e|
|00000300| 63 68 6f 20 49 66 20 74 | 68 69 73 20 61 72 63 68 |cho If t|his arch|
|00000310| 69 76 65 20 69 73 20 63 | 6f 6d 70 6c 65 74 65 2c |ive is c|omplete,|
|00000320| 20 79 6f 75 20 77 69 6c | 6c 20 73 65 65 20 74 68 | you wil|l see th|
|00000330| 65 20 66 6f 6c 6c 6f 77 | 69 6e 67 20 6d 65 73 73 |e follow|ing mess|
|00000340| 61 67 65 3a 0a 65 63 68 | 6f 20 27 20 20 20 20 20 |age:.ech|o ' |
|00000350| 20 20 20 20 20 22 73 68 | 61 72 3a 20 45 6e 64 20 | "sh|ar: End |
|00000360| 6f 66 20 61 72 63 68 69 | 76 65 20 35 20 28 6f 66 |of archi|ve 5 (of|
|00000370| 20 31 36 29 2e 22 27 0a | 69 66 20 74 65 73 74 20 | 16)."'.|if test |
|00000380| 2d 66 20 27 2e 2f 67 61 | 77 6b 2e 74 65 78 69 6e |-f './ga|wk.texin|
|00000390| 66 6f 2e 30 32 27 20 2d | 61 20 22 24 7b 31 7d 22 |fo.02' -|a "${1}"|
|000003a0| 20 21 3d 20 22 2d 63 22 | 20 3b 20 74 68 65 6e 20 | != "-c"| ; then |
|000003b0| 0a 20 20 65 63 68 6f 20 | 73 68 61 72 3a 20 57 69 |. echo |shar: Wi|
|000003c0| 6c 6c 20 6e 6f 74 20 63 | 6c 6f 62 62 65 72 20 65 |ll not c|lobber e|
|000003d0| 78 69 73 74 69 6e 67 20 | 66 69 6c 65 20 5c 22 27 |xisting |file \"'|
|000003e0| 2e 2f 67 61 77 6b 2e 74 | 65 78 69 6e 66 6f 2e 30 |./gawk.t|exinfo.0|
|000003f0| 32 27 5c 22 0a 65 6c 73 | 65 0a 20 20 65 63 68 6f |2'\".els|e. echo|
|00000400| 20 73 68 61 72 3a 20 45 | 78 74 72 61 63 74 69 6e | shar: E|xtractin|
|00000410| 67 20 5c 22 27 2e 2f 67 | 61 77 6b 2e 74 65 78 69 |g \"'./g|awk.texi|
|00000420| 6e 66 6f 2e 30 32 27 5c | 22 20 5c 28 34 39 36 36 |nfo.02'\|" \(4966|
|00000430| 35 20 63 68 61 72 61 63 | 74 65 72 73 5c 29 0a 20 |5 charac|ters\). |
|00000440| 20 73 65 64 20 22 73 2f | 5e 58 2f 2f 22 20 3e 27 | sed "s/|^X//" >'|
|00000450| 2e 2f 67 61 77 6b 2e 74 | 65 78 69 6e 66 6f 2e 30 |./gawk.t|exinfo.0|
|00000460| 32 27 20 3c 3c 27 45 4e | 44 5f 4f 46 5f 46 49 4c |2' <<'EN|D_OF_FIL|
|00000470| 45 27 0a 58 54 68 65 20 | 69 6e 70 75 74 20 69 73 |E'.XThe |input is|
|00000480| 20 72 65 61 64 20 69 6e | 20 75 6e 69 74 73 20 63 | read in| units c|
|00000490| 61 6c 6c 65 64 20 40 64 | 66 6e 7b 72 65 63 6f 72 |alled @d|fn{recor|
|000004a0| 64 73 7d 2c 20 61 6e 64 | 20 70 72 6f 63 65 73 73 |ds}, and| process|
|000004b0| 65 64 20 62 79 20 74 68 | 65 0a 58 72 75 6c 65 73 |ed by th|e.Xrules|
|000004c0| 20 6f 6e 65 20 72 65 63 | 6f 72 64 20 61 74 20 61 | one rec|ord at a|
|000004d0| 20 74 69 6d 65 2e 20 20 | 42 79 20 64 65 66 61 75 | time. |By defau|
|000004e0| 6c 74 2c 20 65 61 63 68 | 20 72 65 63 6f 72 64 20 |lt, each| record |
|000004f0| 69 73 20 6f 6e 65 20 6c | 69 6e 65 2e 20 20 45 61 |is one l|ine. Ea|
|00000500| 63 68 0a 58 72 65 63 6f | 72 64 20 72 65 61 64 20 |ch.Xreco|rd read |
|00000510| 69 73 20 73 70 6c 69 74 | 20 61 75 74 6f 6d 61 74 |is split| automat|
|00000520| 69 63 61 6c 6c 79 20 69 | 6e 74 6f 20 40 64 66 6e |ically i|nto @dfn|
|00000530| 7b 66 69 65 6c 64 73 7d | 2c 20 74 6f 20 6d 61 6b |{fields}|, to mak|
|00000540| 65 20 69 74 20 6d 6f 72 | 65 0a 58 63 6f 6e 76 65 |e it mor|e.Xconve|
|00000550| 6e 69 65 6e 74 20 66 6f | 72 20 61 20 72 75 6c 65 |nient fo|r a rule|
|00000560| 20 74 6f 20 77 6f 72 6b | 20 6f 6e 20 70 61 72 74 | to work| on part|
|00000570| 73 20 6f 66 20 74 68 65 | 20 72 65 63 6f 72 64 20 |s of the| record |
|00000580| 75 6e 64 65 72 0a 58 63 | 6f 6e 73 69 64 65 72 61 |under.Xc|onsidera|
|00000590| 74 69 6f 6e 2e 0a 58 0a | 58 4f 6e 20 72 61 72 65 |tion..X.|XOn rare|
|000005a0| 20 6f 63 63 61 73 69 6f | 6e 73 20 79 6f 75 20 77 | occasio|ns you w|
|000005b0| 69 6c 6c 20 6e 65 65 64 | 20 74 6f 20 75 73 65 20 |ill need| to use |
|000005c0| 74 68 65 20 40 63 6f 64 | 65 7b 67 65 74 6c 69 6e |the @cod|e{getlin|
|000005d0| 65 7d 20 63 6f 6d 6d 61 | 6e 64 2c 0a 58 77 68 69 |e} comma|nd,.Xwhi|
|000005e0| 63 68 20 63 61 6e 20 64 | 6f 20 65 78 70 6c 69 63 |ch can d|o explic|
|000005f0| 69 74 20 69 6e 70 75 74 | 20 66 72 6f 6d 20 61 6e |it input| from an|
|00000600| 79 20 6e 75 6d 62 65 72 | 20 6f 66 20 66 69 6c 65 |y number| of file|
|00000610| 73 20 28 40 70 78 72 65 | 66 7b 47 65 74 6c 69 6e |s (@pxre|f{Getlin|
|00000620| 65 7d 29 2e 0a 58 0a 58 | 40 6d 65 6e 75 0a 58 2a |e})..X.X|@menu.X*|
|00000630| 20 52 65 63 6f 72 64 73 | 3a 3a 20 20 20 20 20 20 | Records|:: |
|00000640| 20 20 20 20 20 20 20 43 | 6f 6e 74 72 6f 6c 6c 69 | C|ontrolli|
|00000650| 6e 67 20 68 6f 77 20 64 | 61 74 61 20 69 73 20 73 |ng how d|ata is s|
|00000660| 70 6c 69 74 20 69 6e 74 | 6f 20 72 65 63 6f 72 64 |plit int|o record|
|00000670| 73 2e 0a 58 2a 20 46 69 | 65 6c 64 73 3a 3a 20 20 |s..X* Fi|elds:: |
|00000680| 20 20 20 20 20 20 20 20 | 20 20 20 20 41 6e 20 69 | | An i|
|00000690| 6e 74 72 6f 64 75 63 74 | 69 6f 6e 20 74 6f 20 66 |ntroduct|ion to f|
|000006a0| 69 65 6c 64 73 2e 0a 58 | 2a 20 4e 6f 6e 2d 43 6f |ields..X|* Non-Co|
|000006b0| 6e 73 74 61 6e 74 20 46 | 69 65 6c 64 73 3a 3a 20 |nstant F|ields:: |
|000006c0| 4e 6f 6e 2d 63 6f 6e 73 | 74 61 6e 74 20 46 69 65 |Non-cons|tant Fie|
|000006d0| 6c 64 20 4e 75 6d 62 65 | 72 73 2e 0a 58 2a 20 43 |ld Numbe|rs..X* C|
|000006e0| 68 61 6e 67 69 6e 67 20 | 46 69 65 6c 64 73 3a 3a |hanging |Fields::|
|000006f0| 20 20 20 20 20 43 68 61 | 6e 67 69 6e 67 20 74 68 | Cha|nging th|
|00000700| 65 20 43 6f 6e 74 65 6e | 74 73 20 6f 66 20 61 20 |e Conten|ts of a |
|00000710| 46 69 65 6c 64 2e 0a 58 | 2a 20 46 69 65 6c 64 20 |Field..X|* Field |
|00000720| 53 65 70 61 72 61 74 6f | 72 73 3a 3a 20 20 20 20 |Separato|rs:: |
|00000730| 54 68 65 20 66 69 65 6c | 64 20 73 65 70 61 72 61 |The fiel|d separa|
|00000740| 74 6f 72 20 61 6e 64 20 | 68 6f 77 20 74 6f 20 63 |tor and |how to c|
|00000750| 68 61 6e 67 65 20 69 74 | 2e 0a 58 2a 20 4d 75 6c |hange it|..X* Mul|
|00000760| 74 69 70 6c 65 20 4c 69 | 6e 65 3a 3a 20 20 20 20 |tiple Li|ne:: |
|00000770| 20 20 20 52 65 61 64 69 | 6e 67 20 6d 75 6c 74 69 | Readi|ng multi|
|00000780| 2d 6c 69 6e 65 20 72 65 | 63 6f 72 64 73 2e 0a 58 |-line re|cords..X|
|00000790| 0a 58 2a 20 47 65 74 6c | 69 6e 65 3a 3a 20 20 20 |.X* Getl|ine:: |
|000007a0| 20 20 20 20 20 20 20 20 | 20 20 52 65 61 64 69 6e | | Readin|
|000007b0| 67 20 66 69 6c 65 73 20 | 75 6e 64 65 72 20 65 78 |g files |under ex|
|000007c0| 70 6c 69 63 69 74 20 70 | 72 6f 67 72 61 6d 20 63 |plicit p|rogram c|
|000007d0| 6f 6e 74 72 6f 6c 0a 58 | 20 20 20 20 20 20 20 20 |ontrol.X| |
|000007e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000007f0| 75 73 69 6e 67 20 74 68 | 65 20 40 63 6f 64 65 7b |using th|e @code{|
|00000800| 67 65 74 6c 69 6e 65 7d | 20 66 75 6e 63 74 69 6f |getline}| functio|
|00000810| 6e 2e 0a 58 0a 58 2a 20 | 43 6c 6f 73 65 20 49 6e |n..X.X* |Close In|
|00000820| 70 75 74 3a 3a 20 20 20 | 20 20 20 20 20 20 43 6c |put:: | Cl|
|00000830| 6f 73 69 6e 67 20 61 6e | 20 69 6e 70 75 74 20 66 |osing an| input f|
|00000840| 69 6c 65 20 28 73 6f 20 | 79 6f 75 20 63 61 6e 20 |ile (so |you can |
|00000850| 72 65 61 64 20 66 72 6f | 6d 0a 58 20 20 20 20 20 |read fro|m.X |
|00000860| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000870| 20 20 20 74 68 65 20 62 | 65 67 69 6e 6e 69 6e 67 | the b|eginning|
|00000880| 20 6f 6e 63 65 20 6d 6f | 72 65 29 2e 0a 58 40 65 | once mo|re)..X@e|
|00000890| 6e 64 20 6d 65 6e 75 0a | 58 0a 58 40 6e 6f 64 65 |nd menu.|X.X@node|
|000008a0| 20 52 65 63 6f 72 64 73 | 2c 20 46 69 65 6c 64 73 | Records|, Fields|
|000008b0| 2c 20 52 65 61 64 69 6e | 67 20 46 69 6c 65 73 2c |, Readin|g Files,|
|000008c0| 20 52 65 61 64 69 6e 67 | 20 46 69 6c 65 73 0a 58 | Reading| Files.X|
|000008d0| 40 73 65 63 74 69 6f 6e | 20 48 6f 77 20 49 6e 70 |@section| How Inp|
|000008e0| 75 74 20 69 73 20 53 70 | 6c 69 74 20 69 6e 74 6f |ut is Sp|lit into|
|000008f0| 20 52 65 63 6f 72 64 73 | 0a 58 0a 58 40 63 69 6e | Records|.X.X@cin|
|00000900| 64 65 78 20 72 65 63 6f | 72 64 20 73 65 70 61 72 |dex reco|rd separ|
|00000910| 61 74 6f 72 0a 58 54 68 | 65 20 40 63 6f 64 65 7b |ator.XTh|e @code{|
|00000920| 61 77 6b 7d 20 6c 61 6e | 67 75 61 67 65 20 64 69 |awk} lan|guage di|
|00000930| 76 69 64 65 73 20 69 74 | 73 20 69 6e 70 75 74 20 |vides it|s input |
|00000940| 69 6e 74 6f 20 72 65 63 | 6f 72 64 73 20 61 6e 64 |into rec|ords and|
|00000950| 20 66 69 65 6c 64 73 2e | 0a 58 52 65 63 6f 72 64 | fields.|.XRecord|
|00000960| 73 20 61 72 65 20 73 65 | 70 61 72 61 74 65 64 20 |s are se|parated |
|00000970| 62 79 20 61 20 63 68 61 | 72 61 63 74 65 72 20 63 |by a cha|racter c|
|00000980| 61 6c 6c 65 64 20 74 68 | 65 20 40 64 66 6e 7b 72 |alled th|e @dfn{r|
|00000990| 65 63 6f 72 64 20 73 65 | 70 61 72 61 74 6f 72 7d |ecord se|parator}|
|000009a0| 2e 0a 58 42 79 20 64 65 | 66 61 75 6c 74 2c 20 74 |..XBy de|fault, t|
|000009b0| 68 65 20 72 65 63 6f 72 | 64 20 73 65 70 61 72 61 |he recor|d separa|
|000009c0| 74 6f 72 20 69 73 20 74 | 68 65 20 6e 65 77 6c 69 |tor is t|he newli|
|000009d0| 6e 65 20 63 68 61 72 61 | 63 74 65 72 2e 20 20 54 |ne chara|cter. T|
|000009e0| 68 65 72 65 66 6f 72 65 | 2c 0a 58 6e 6f 72 6d 61 |herefore|,.Xnorma|
|000009f0| 6c 6c 79 2c 20 61 20 72 | 65 63 6f 72 64 20 69 73 |lly, a r|ecord is|
|00000a00| 20 61 20 6c 69 6e 65 20 | 6f 66 20 74 65 78 74 2e | a line |of text.|
|00000a10| 40 72 65 66 69 6c 6c 0a | 58 0a 58 40 63 20 40 63 |@refill.|X.X@c @c|
|00000a20| 69 6e 64 65 78 20 63 68 | 61 6e 67 69 6e 67 20 74 |index ch|anging t|
|00000a30| 68 65 20 72 65 63 6f 72 | 64 20 73 65 70 61 72 61 |he recor|d separa|
|00000a40| 74 6f 72 0a 58 40 76 69 | 6e 64 65 78 20 52 53 0a |tor.X@vi|ndex RS.|
|00000a50| 58 53 6f 6d 65 74 69 6d | 65 73 20 79 6f 75 20 6d |XSometim|es you m|
|00000a60| 61 79 20 77 61 6e 74 20 | 74 6f 20 75 73 65 20 61 |ay want |to use a|
|00000a70| 20 64 69 66 66 65 72 65 | 6e 74 20 63 68 61 72 61 | differe|nt chara|
|00000a80| 63 74 65 72 20 74 6f 20 | 73 65 70 61 72 61 74 65 |cter to |separate|
|00000a90| 20 79 6f 75 72 0a 58 72 | 65 63 6f 72 64 73 2e 20 | your.Xr|ecords. |
|00000aa0| 20 59 6f 75 20 63 61 6e | 20 75 73 65 20 64 69 66 | You can| use dif|
|00000ab0| 66 65 72 65 6e 74 20 63 | 68 61 72 61 63 74 65 72 |ferent c|haracter|
|00000ac0| 73 20 62 79 20 63 68 61 | 6e 67 69 6e 67 20 74 68 |s by cha|nging th|
|00000ad0| 65 20 62 75 69 6c 74 2d | 69 6e 0a 58 76 61 72 69 |e built-|in.Xvari|
|00000ae0| 61 62 6c 65 20 40 63 6f | 64 65 7b 52 53 7d 2e 20 |able @co|de{RS}. |
|00000af0| 20 0a 58 0a 58 54 68 65 | 20 76 61 6c 75 65 20 6f | .X.XThe| value o|
|00000b00| 66 20 40 63 6f 64 65 7b | 52 53 7d 20 69 73 20 61 |f @code{|RS} is a|
|00000b10| 20 73 74 72 69 6e 67 20 | 74 68 61 74 20 73 61 79 | string |that say|
|00000b20| 73 20 68 6f 77 20 74 6f | 20 73 65 70 61 72 61 74 |s how to| separat|
|00000b30| 65 20 72 65 63 6f 72 64 | 73 3b 0a 58 74 68 65 20 |e record|s;.Xthe |
|00000b40| 64 65 66 61 75 6c 74 20 | 76 61 6c 75 65 20 69 73 |default |value is|
|00000b50| 20 40 63 6f 64 65 7b 22 | 5c 6e 22 7d 2c 20 74 68 | @code{"|\n"}, th|
|00000b60| 65 20 73 74 72 69 6e 67 | 20 6f 66 20 6a 75 73 74 |e string| of just|
|00000b70| 20 61 20 6e 65 77 6c 69 | 6e 65 0a 58 63 68 61 72 | a newli|ne.Xchar|
|00000b80| 61 63 74 65 72 2e 20 20 | 54 68 69 73 20 69 73 20 |acter. |This is |
|00000b90| 77 68 79 20 72 65 63 6f | 72 64 73 20 61 72 65 2c |why reco|rds are,|
|00000ba0| 20 62 79 20 64 65 66 61 | 75 6c 74 2c 20 73 69 6e | by defa|ult, sin|
|00000bb0| 67 6c 65 20 6c 69 6e 65 | 73 2e 0a 58 0a 58 40 63 |gle line|s..X.X@c|
|00000bc0| 6f 64 65 7b 52 53 7d 20 | 63 61 6e 20 68 61 76 65 |ode{RS} |can have|
|00000bd0| 20 61 6e 79 20 73 74 72 | 69 6e 67 20 61 73 20 69 | any str|ing as i|
|00000be0| 74 73 20 76 61 6c 75 65 | 2c 20 62 75 74 20 6f 6e |ts value|, but on|
|00000bf0| 6c 79 20 74 68 65 20 66 | 69 72 73 74 20 63 68 61 |ly the f|irst cha|
|00000c00| 72 61 63 74 65 72 0a 58 | 6f 66 20 74 68 65 20 73 |racter.X|of the s|
|00000c10| 74 72 69 6e 67 20 69 73 | 20 75 73 65 64 20 61 73 |tring is| used as|
|00000c20| 20 74 68 65 20 72 65 63 | 6f 72 64 20 73 65 70 61 | the rec|ord sepa|
|00000c30| 72 61 74 6f 72 2e 20 20 | 54 68 65 20 6f 74 68 65 |rator. |The othe|
|00000c40| 72 20 63 68 61 72 61 63 | 74 65 72 73 20 61 72 65 |r charac|ters are|
|00000c50| 0a 58 69 67 6e 6f 72 65 | 64 2e 20 20 40 63 6f 64 |.Xignore|d. @cod|
|00000c60| 65 7b 52 53 7d 20 69 73 | 20 65 78 63 65 70 74 69 |e{RS} is| excepti|
|00000c70| 6f 6e 61 6c 20 69 6e 20 | 74 68 69 73 20 72 65 67 |onal in |this reg|
|00000c80| 61 72 64 3b 20 40 63 6f | 64 65 7b 61 77 6b 7d 20 |ard; @co|de{awk} |
|00000c90| 75 73 65 73 20 74 68 65 | 0a 58 66 75 6c 6c 20 76 |uses the|.Xfull v|
|00000ca0| 61 6c 75 65 20 6f 66 20 | 61 6c 6c 20 69 74 73 20 |alue of |all its |
|00000cb0| 6f 74 68 65 72 20 62 75 | 69 6c 74 2d 69 6e 20 76 |other bu|ilt-in v|
|00000cc0| 61 72 69 61 62 6c 65 73 | 2e 40 72 65 66 69 6c 6c |ariables|.@refill|
|00000cd0| 0a 58 0a 58 40 69 67 6e | 6f 72 65 0a 58 53 6f 6d |.X.X@ign|ore.XSom|
|00000ce0| 65 64 61 79 20 74 68 69 | 73 20 73 68 6f 75 6c 64 |eday thi|s should|
|00000cf0| 20 62 65 20 74 72 75 65 | 21 0a 58 0a 58 54 68 65 | be true|!.X.XThe|
|00000d00| 20 76 61 6c 75 65 20 6f | 66 20 40 63 6f 64 65 7b | value o|f @code{|
|00000d10| 52 53 7d 20 69 73 20 6e | 6f 74 20 6c 69 6d 69 74 |RS} is n|ot limit|
|00000d20| 65 64 20 74 6f 20 61 20 | 6f 6e 65 2d 63 68 61 72 |ed to a |one-char|
|00000d30| 61 63 74 65 72 20 73 74 | 72 69 6e 67 2e 20 20 49 |acter st|ring. I|
|00000d40| 74 20 63 61 6e 0a 58 62 | 65 20 61 6e 79 20 72 65 |t can.Xb|e any re|
|00000d50| 67 75 6c 61 72 20 65 78 | 70 72 65 73 73 69 6f 6e |gular ex|pression|
|00000d60| 20 28 40 70 78 72 65 66 | 7b 52 65 67 65 78 70 7d | (@pxref|{Regexp}|
|00000d70| 29 2e 20 20 49 6e 20 67 | 65 6e 65 72 61 6c 2c 20 |). In g|eneral, |
|00000d80| 65 61 63 68 20 72 65 63 | 6f 72 64 0a 58 65 6e 64 |each rec|ord.Xend|
|00000d90| 73 20 61 74 20 74 68 65 | 20 6e 65 78 74 20 73 74 |s at the| next st|
|00000da0| 72 69 6e 67 20 74 68 61 | 74 20 6d 61 74 63 68 65 |ring tha|t matche|
|00000db0| 73 20 74 68 65 20 72 65 | 67 75 6c 61 72 20 65 78 |s the re|gular ex|
|00000dc0| 70 72 65 73 73 69 6f 6e | 3b 20 74 68 65 20 6e 65 |pression|; the ne|
|00000dd0| 78 74 0a 58 72 65 63 6f | 72 64 20 73 74 61 72 74 |xt.Xreco|rd start|
|00000de0| 73 20 61 74 20 74 68 65 | 20 65 6e 64 20 6f 66 20 |s at the| end of |
|00000df0| 74 68 65 20 6d 61 74 63 | 68 69 6e 67 20 73 74 72 |the matc|hing str|
|00000e00| 69 6e 67 2e 20 20 54 68 | 69 73 20 67 65 6e 65 72 |ing. Th|is gener|
|00000e10| 61 6c 20 72 75 6c 65 20 | 69 73 0a 58 61 63 74 75 |al rule |is.Xactu|
|00000e20| 61 6c 6c 79 20 61 74 20 | 77 6f 72 6b 20 69 6e 20 |ally at |work in |
|00000e30| 74 68 65 20 75 73 75 61 | 6c 20 63 61 73 65 2c 20 |the usua|l case, |
|00000e40| 77 68 65 72 65 20 40 63 | 6f 64 65 7b 52 53 7d 20 |where @c|ode{RS} |
|00000e50| 63 6f 6e 74 61 69 6e 73 | 20 6a 75 73 74 20 61 0a |contains| just a.|
|00000e60| 58 6e 65 77 6c 69 6e 65 | 3a 20 61 20 72 65 63 6f |Xnewline|: a reco|
|00000e70| 72 64 20 65 6e 64 73 20 | 61 74 20 74 68 65 20 62 |rd ends |at the b|
|00000e80| 65 67 69 6e 6e 69 6e 67 | 20 6f 66 20 74 68 65 20 |eginning| of the |
|00000e90| 6e 65 78 74 20 6d 61 74 | 63 68 69 6e 67 20 73 74 |next mat|ching st|
|00000ea0| 72 69 6e 67 20 28 74 68 | 65 0a 58 6e 65 78 74 20 |ring (th|e.Xnext |
|00000eb0| 6e 65 77 6c 69 6e 65 20 | 69 6e 20 74 68 65 20 69 |newline |in the i|
|00000ec0| 6e 70 75 74 29 20 61 6e | 64 20 74 68 65 20 66 6f |nput) an|d the fo|
|00000ed0| 6c 6c 6f 77 69 6e 67 20 | 72 65 63 6f 72 64 20 73 |llowing |record s|
|00000ee0| 74 61 72 74 73 20 6a 75 | 73 74 20 61 66 74 65 72 |tarts ju|st after|
|00000ef0| 0a 58 74 68 65 20 65 6e | 64 20 6f 66 20 74 68 69 |.Xthe en|d of thi|
|00000f00| 73 20 73 74 72 69 6e 67 | 20 28 61 74 20 74 68 65 |s string| (at the|
|00000f10| 20 66 69 72 73 74 20 63 | 68 61 72 61 63 74 65 72 | first c|haracter|
|00000f20| 20 6f 66 20 74 68 65 20 | 66 6f 6c 6c 6f 77 69 6e | of the |followin|
|00000f30| 67 20 6c 69 6e 65 29 2e | 0a 58 54 68 65 20 6e 65 |g line).|.XThe ne|
|00000f40| 77 6c 69 6e 65 2c 20 73 | 69 6e 63 65 20 69 74 20 |wline, s|ince it |
|00000f50| 6d 61 74 63 68 65 73 20 | 40 63 6f 64 65 7b 52 53 |matches |@code{RS|
|00000f60| 7d 2c 20 69 73 20 6e 6f | 74 20 70 61 72 74 20 6f |}, is no|t part o|
|00000f70| 66 20 65 69 74 68 65 72 | 20 72 65 63 6f 72 64 2e |f either| record.|
|00000f80| 0a 58 40 65 6e 64 20 69 | 67 6e 6f 72 65 0a 58 0a |.X@end i|gnore.X.|
|00000f90| 58 59 6f 75 20 63 61 6e | 20 63 68 61 6e 67 65 20 |XYou can| change |
|00000fa0| 74 68 65 20 76 61 6c 75 | 65 20 6f 66 20 40 63 6f |the valu|e of @co|
|00000fb0| 64 65 7b 52 53 7d 20 69 | 6e 20 74 68 65 20 40 63 |de{RS} i|n the @c|
|00000fc0| 6f 64 65 7b 61 77 6b 7d | 20 70 72 6f 67 72 61 6d |ode{awk}| program|
|00000fd0| 20 77 69 74 68 20 74 68 | 65 0a 58 61 73 73 69 67 | with th|e.Xassig|
|00000fe0| 6e 6d 65 6e 74 20 6f 70 | 65 72 61 74 6f 72 2c 20 |nment op|erator, |
|00000ff0| 40 73 61 6d 70 7b 3d 7d | 20 28 40 70 78 72 65 66 |@samp{=}| (@pxref|
|00001000| 7b 41 73 73 69 67 6e 6d | 65 6e 74 20 4f 70 73 7d |{Assignm|ent Ops}|
|00001010| 29 2e 20 20 54 68 65 20 | 6e 65 77 0a 58 72 65 63 |). The |new.Xrec|
|00001020| 6f 72 64 2d 73 65 70 61 | 72 61 74 6f 72 20 63 68 |ord-sepa|rator ch|
|00001030| 61 72 61 63 74 65 72 20 | 73 68 6f 75 6c 64 20 62 |aracter |should b|
|00001040| 65 20 65 6e 63 6c 6f 73 | 65 64 20 69 6e 20 71 75 |e enclos|ed in qu|
|00001050| 6f 74 61 74 69 6f 6e 20 | 6d 61 72 6b 73 20 74 6f |otation |marks to|
|00001060| 20 6d 61 6b 65 0a 58 61 | 20 73 74 72 69 6e 67 20 | make.Xa| string |
|00001070| 63 6f 6e 73 74 61 6e 74 | 2e 20 20 4f 66 74 65 6e |constant|. Often|
|00001080| 20 74 68 65 20 72 69 67 | 68 74 20 74 69 6d 65 20 | the rig|ht time |
|00001090| 74 6f 20 64 6f 20 74 68 | 69 73 20 69 73 20 61 74 |to do th|is is at|
|000010a0| 20 74 68 65 20 62 65 67 | 69 6e 6e 69 6e 67 0a 58 | the beg|inning.X|
|000010b0| 6f 66 20 65 78 65 63 75 | 74 69 6f 6e 2c 20 62 65 |of execu|tion, be|
|000010c0| 66 6f 72 65 20 61 6e 79 | 20 69 6e 70 75 74 20 68 |fore any| input h|
|000010d0| 61 73 20 62 65 65 6e 20 | 70 72 6f 63 65 73 73 65 |as been |processe|
|000010e0| 64 2c 20 73 6f 20 74 68 | 61 74 20 74 68 65 20 76 |d, so th|at the v|
|000010f0| 65 72 79 0a 58 66 69 72 | 73 74 20 72 65 63 6f 72 |ery.Xfir|st recor|
|00001100| 64 20 77 69 6c 6c 20 62 | 65 20 72 65 61 64 20 77 |d will b|e read w|
|00001110| 69 74 68 20 74 68 65 20 | 70 72 6f 70 65 72 20 73 |ith the |proper s|
|00001120| 65 70 61 72 61 74 6f 72 | 2e 20 20 54 6f 20 64 6f |eparator|. To do|
|00001130| 20 74 68 69 73 2c 20 75 | 73 65 0a 58 74 68 65 20 | this, u|se.Xthe |
|00001140| 73 70 65 63 69 61 6c 20 | 40 63 6f 64 65 7b 42 45 |special |@code{BE|
|00001150| 47 49 4e 7d 20 70 61 74 | 74 65 72 6e 20 28 40 70 |GIN} pat|tern (@p|
|00001160| 78 72 65 66 7b 42 45 47 | 49 4e 2f 45 4e 44 7d 29 |xref{BEG|IN/END})|
|00001170| 2e 20 20 46 6f 72 0a 58 | 65 78 61 6d 70 6c 65 3a |. For.X|example:|
|00001180| 40 72 65 66 69 6c 6c 0a | 58 0a 58 40 65 78 61 6d |@refill.|X.X@exam|
|00001190| 70 6c 65 0a 58 61 77 6b | 20 27 42 45 47 49 4e 20 |ple.Xawk| 'BEGIN |
|000011a0| 40 7b 20 52 53 20 3d 20 | 22 2f 22 20 40 7d 20 3b |@{ RS = |"/" @} ;|
|000011b0| 20 40 7b 20 70 72 69 6e | 74 20 24 30 20 40 7d 27 | @{ prin|t $0 @}'|
|000011c0| 20 42 42 53 2d 6c 69 73 | 74 0a 58 40 65 6e 64 20 | BBS-lis|t.X@end |
|000011d0| 65 78 61 6d 70 6c 65 0a | 58 0a 58 40 6e 6f 69 6e |example.|X.X@noin|
|000011e0| 64 65 6e 74 0a 58 63 68 | 61 6e 67 65 73 20 74 68 |dent.Xch|anges th|
|000011f0| 65 20 76 61 6c 75 65 20 | 6f 66 20 40 63 6f 64 65 |e value |of @code|
|00001200| 7b 52 53 7d 20 74 6f 20 | 40 63 6f 64 65 7b 22 2f |{RS} to |@code{"/|
|00001210| 22 7d 2c 20 62 65 66 6f | 72 65 20 72 65 61 64 69 |"}, befo|re readi|
|00001220| 6e 67 20 61 6e 79 20 69 | 6e 70 75 74 2e 0a 58 54 |ng any i|nput..XT|
|00001230| 68 69 73 20 69 73 20 61 | 20 73 74 72 69 6e 67 20 |his is a| string |
|00001240| 77 68 6f 73 65 20 66 69 | 72 73 74 20 63 68 61 72 |whose fi|rst char|
|00001250| 61 63 74 65 72 20 69 73 | 20 61 20 73 6c 61 73 68 |acter is| a slash|
|00001260| 3b 20 61 73 20 61 20 72 | 65 73 75 6c 74 2c 20 72 |; as a r|esult, r|
|00001270| 65 63 6f 72 64 73 0a 58 | 61 72 65 20 73 65 70 61 |ecords.X|are sepa|
|00001280| 72 61 74 65 64 20 62 79 | 20 73 6c 61 73 68 65 73 |rated by| slashes|
|00001290| 2e 20 20 54 68 65 6e 20 | 74 68 65 20 69 6e 70 75 |. Then |the inpu|
|000012a0| 74 20 66 69 6c 65 20 69 | 73 20 72 65 61 64 2c 20 |t file i|s read, |
|000012b0| 61 6e 64 20 74 68 65 20 | 73 65 63 6f 6e 64 0a 58 |and the |second.X|
|000012c0| 72 75 6c 65 20 69 6e 20 | 74 68 65 20 40 63 6f 64 |rule in |the @cod|
|000012d0| 65 7b 61 77 6b 7d 20 70 | 72 6f 67 72 61 6d 20 28 |e{awk} p|rogram (|
|000012e0| 74 68 65 20 61 63 74 69 | 6f 6e 20 77 69 74 68 20 |the acti|on with |
|000012f0| 6e 6f 20 70 61 74 74 65 | 72 6e 29 20 70 72 69 6e |no patte|rn) prin|
|00001300| 74 73 20 65 61 63 68 0a | 58 72 65 63 6f 72 64 2e |ts each.|Xrecord.|
|00001310| 20 20 53 69 6e 63 65 20 | 65 61 63 68 20 40 63 6f | Since |each @co|
|00001320| 64 65 7b 70 72 69 6e 74 | 7d 20 73 74 61 74 65 6d |de{print|} statem|
|00001330| 65 6e 74 20 61 64 64 73 | 20 61 20 6e 65 77 6c 69 |ent adds| a newli|
|00001340| 6e 65 20 61 74 20 74 68 | 65 20 65 6e 64 20 6f 66 |ne at th|e end of|
|00001350| 0a 58 69 74 73 20 6f 75 | 74 70 75 74 2c 20 74 68 |.Xits ou|tput, th|
|00001360| 65 20 65 66 66 65 63 74 | 20 6f 66 20 74 68 69 73 |e effect| of this|
|00001370| 20 40 63 6f 64 65 7b 61 | 77 6b 7d 20 70 72 6f 67 | @code{a|wk} prog|
|00001380| 72 61 6d 20 69 73 20 74 | 6f 20 63 6f 70 79 20 74 |ram is t|o copy t|
|00001390| 68 65 20 69 6e 70 75 74 | 0a 58 77 69 74 68 20 65 |he input|.Xwith e|
|000013a0| 61 63 68 20 73 6c 61 73 | 68 20 63 68 61 6e 67 65 |ach slas|h change|
|000013b0| 64 20 74 6f 20 61 20 6e | 65 77 6c 69 6e 65 2e 0a |d to a n|ewline..|
|000013c0| 58 0a 58 41 6e 6f 74 68 | 65 72 20 77 61 79 20 74 |X.XAnoth|er way t|
|000013d0| 6f 20 63 68 61 6e 67 65 | 20 74 68 65 20 72 65 63 |o change| the rec|
|000013e0| 6f 72 64 20 73 65 70 61 | 72 61 74 6f 72 20 69 73 |ord sepa|rator is|
|000013f0| 20 6f 6e 20 74 68 65 20 | 63 6f 6d 6d 61 6e 64 20 | on the |command |
|00001400| 6c 69 6e 65 2c 0a 58 75 | 73 69 6e 67 20 74 68 65 |line,.Xu|sing the|
|00001410| 20 76 61 72 69 61 62 6c | 65 2d 61 73 73 69 67 6e | variabl|e-assign|
|00001420| 6d 65 6e 74 20 66 65 61 | 74 75 72 65 20 28 40 70 |ment fea|ture (@p|
|00001430| 78 72 65 66 7b 43 6f 6d | 6d 61 6e 64 20 4c 69 6e |xref{Com|mand Lin|
|00001440| 65 7d 29 2e 0a 58 0a 58 | 40 65 78 61 6d 70 6c 65 |e})..X.X|@example|
|00001450| 0a 58 61 77 6b 20 27 40 | 64 6f 74 73 7b 7d 27 20 |.Xawk '@|dots{}' |
|00001460| 52 53 3d 22 2f 22 20 40 | 76 61 72 7b 73 6f 75 72 |RS="/" @|var{sour|
|00001470| 63 65 2d 66 69 6c 65 7d | 0a 58 40 65 6e 64 20 65 |ce-file}|.X@end e|
|00001480| 78 61 6d 70 6c 65 0a 58 | 0a 58 40 6e 6f 69 6e 64 |xample.X|.X@noind|
|00001490| 65 6e 74 0a 58 54 68 69 | 73 20 73 65 74 73 20 40 |ent.XThi|s sets @|
|000014a0| 63 6f 64 65 7b 52 53 7d | 20 74 6f 20 40 73 61 6d |code{RS}| to @sam|
|000014b0| 70 7b 2f 7d 20 62 65 66 | 6f 72 65 20 70 72 6f 63 |p{/} bef|ore proc|
|000014c0| 65 73 73 69 6e 67 20 40 | 76 61 72 7b 73 6f 75 72 |essing @|var{sour|
|000014d0| 63 65 2d 66 69 6c 65 7d | 2e 0a 58 0a 58 54 68 65 |ce-file}|..X.XThe|
|000014e0| 20 65 6d 70 74 79 20 73 | 74 72 69 6e 67 20 28 61 | empty s|tring (a|
|000014f0| 20 73 74 72 69 6e 67 20 | 6f 66 20 6e 6f 20 63 68 | string |of no ch|
|00001500| 61 72 61 63 74 65 72 73 | 29 20 68 61 73 20 61 20 |aracters|) has a |
|00001510| 73 70 65 63 69 61 6c 20 | 6d 65 61 6e 69 6e 67 0a |special |meaning.|
|00001520| 58 61 73 20 74 68 65 20 | 76 61 6c 75 65 20 6f 66 |Xas the |value of|
|00001530| 20 40 63 6f 64 65 7b 52 | 53 7d 3a 20 69 74 20 6d | @code{R|S}: it m|
|00001540| 65 61 6e 73 20 74 68 61 | 74 20 72 65 63 6f 72 64 |eans tha|t record|
|00001550| 73 20 61 72 65 20 73 65 | 70 61 72 61 74 65 64 20 |s are se|parated |
|00001560| 6f 6e 6c 79 0a 58 62 79 | 20 62 6c 61 6e 6b 20 6c |only.Xby| blank l|
|00001570| 69 6e 65 73 2e 20 20 40 | 78 72 65 66 7b 4d 75 6c |ines. @|xref{Mul|
|00001580| 74 69 70 6c 65 20 4c 69 | 6e 65 7d 2c 20 66 6f 72 |tiple Li|ne}, for|
|00001590| 20 6d 6f 72 65 20 64 65 | 74 61 69 6c 73 2e 0a 58 | more de|tails..X|
|000015a0| 0a 58 40 63 69 6e 64 65 | 78 20 6e 75 6d 62 65 72 |.X@cinde|x number|
|000015b0| 20 6f 66 20 72 65 63 6f | 72 64 73 2c 20 40 63 6f | of reco|rds, @co|
|000015c0| 64 65 7b 4e 52 7d 20 6f | 72 20 40 63 6f 64 65 7b |de{NR} o|r @code{|
|000015d0| 46 4e 52 7d 0a 58 40 76 | 69 6e 64 65 78 20 4e 52 |FNR}.X@v|index NR|
|000015e0| 0a 58 40 76 69 6e 64 65 | 78 20 46 4e 52 0a 58 54 |.X@vinde|x FNR.XT|
|000015f0| 68 65 20 40 63 6f 64 65 | 7b 61 77 6b 7d 20 75 74 |he @code|{awk} ut|
|00001600| 69 6c 69 74 79 20 6b 65 | 65 70 73 20 74 72 61 63 |ility ke|eps trac|
|00001610| 6b 20 6f 66 20 74 68 65 | 20 6e 75 6d 62 65 72 20 |k of the| number |
|00001620| 6f 66 20 72 65 63 6f 72 | 64 73 20 74 68 61 74 20 |of recor|ds that |
|00001630| 68 61 76 65 0a 58 62 65 | 65 6e 20 72 65 61 64 20 |have.Xbe|en read |
|00001640| 73 6f 20 66 61 72 20 66 | 72 6f 6d 20 74 68 65 20 |so far f|rom the |
|00001650| 63 75 72 72 65 6e 74 20 | 69 6e 70 75 74 20 66 69 |current |input fi|
|00001660| 6c 65 2e 20 20 54 68 69 | 73 20 76 61 6c 75 65 20 |le. Thi|s value |
|00001670| 69 73 20 73 74 6f 72 65 | 64 20 69 6e 20 61 0a 58 |is store|d in a.X|
|00001680| 62 75 69 6c 74 2d 69 6e | 20 76 61 72 69 61 62 6c |built-in| variabl|
|00001690| 65 20 63 61 6c 6c 65 64 | 20 40 63 6f 64 65 7b 46 |e called| @code{F|
|000016a0| 4e 52 7d 2e 20 20 49 74 | 20 69 73 20 72 65 73 65 |NR}. It| is rese|
|000016b0| 74 20 74 6f 20 7a 65 72 | 6f 20 77 68 65 6e 20 61 |t to zer|o when a|
|000016c0| 20 6e 65 77 0a 58 66 69 | 6c 65 20 69 73 20 73 74 | new.Xfi|le is st|
|000016d0| 61 72 74 65 64 2e 20 20 | 41 6e 6f 74 68 65 72 20 |arted. |Another |
|000016e0| 62 75 69 6c 74 2d 69 6e | 20 76 61 72 69 61 62 6c |built-in| variabl|
|000016f0| 65 2c 20 40 63 6f 64 65 | 7b 4e 52 7d 2c 20 69 73 |e, @code|{NR}, is|
|00001700| 20 74 68 65 20 74 6f 74 | 61 6c 0a 58 6e 75 6d 62 | the tot|al.Xnumb|
|00001710| 65 72 20 6f 66 20 69 6e | 70 75 74 20 72 65 63 6f |er of in|put reco|
|00001720| 72 64 73 20 72 65 61 64 | 20 73 6f 20 66 61 72 20 |rds read| so far |
|00001730| 66 72 6f 6d 20 61 6c 6c | 20 66 69 6c 65 73 2e 20 |from all| files. |
|00001740| 20 49 74 20 73 74 61 72 | 74 73 20 61 74 20 7a 65 | It star|ts at ze|
|00001750| 72 6f 0a 58 62 75 74 20 | 69 73 20 6e 65 76 65 72 |ro.Xbut |is never|
|00001760| 20 61 75 74 6f 6d 61 74 | 69 63 61 6c 6c 79 20 72 | automat|ically r|
|00001770| 65 73 65 74 20 74 6f 20 | 7a 65 72 6f 2e 0a 58 0a |eset to |zero..X.|
|00001780| 58 49 66 20 79 6f 75 20 | 63 68 61 6e 67 65 20 74 |XIf you |change t|
|00001790| 68 65 20 76 61 6c 75 65 | 20 6f 66 20 40 63 6f 64 |he value| of @cod|
|000017a0| 65 7b 52 53 7d 20 69 6e | 20 74 68 65 20 6d 69 64 |e{RS} in| the mid|
|000017b0| 64 6c 65 20 6f 66 20 61 | 6e 20 40 63 6f 64 65 7b |dle of a|n @code{|
|000017c0| 61 77 6b 7d 20 72 75 6e | 2c 0a 58 74 68 65 20 6e |awk} run|,.Xthe n|
|000017d0| 65 77 20 76 61 6c 75 65 | 20 69 73 20 75 73 65 64 |ew value| is used|
|000017e0| 20 74 6f 20 64 65 6c 69 | 6d 69 74 20 73 75 62 73 | to deli|mit subs|
|000017f0| 65 71 75 65 6e 74 20 72 | 65 63 6f 72 64 73 2c 20 |equent r|ecords, |
|00001800| 62 75 74 20 74 68 65 20 | 72 65 63 6f 72 64 0a 58 |but the |record.X|
|00001810| 63 75 72 72 65 6e 74 6c | 79 20 62 65 69 6e 67 20 |currentl|y being |
|00001820| 70 72 6f 63 65 73 73 65 | 64 20 28 61 6e 64 20 72 |processe|d (and r|
|00001830| 65 63 6f 72 64 73 20 61 | 6c 72 65 61 64 79 20 66 |ecords a|lready f|
|00001840| 69 6e 69 73 68 65 64 29 | 20 61 72 65 20 6e 6f 74 |inished)| are not|
|00001850| 0a 58 61 66 66 65 63 74 | 65 64 2e 0a 58 0a 58 40 |.Xaffect|ed..X.X@|
|00001860| 6e 6f 64 65 20 46 69 65 | 6c 64 73 2c 20 4e 6f 6e |node Fie|lds, Non|
|00001870| 2d 43 6f 6e 73 74 61 6e | 74 20 46 69 65 6c 64 73 |-Constan|t Fields|
|00001880| 2c 20 52 65 63 6f 72 64 | 73 2c 20 52 65 61 64 69 |, Record|s, Readi|
|00001890| 6e 67 20 46 69 6c 65 73 | 0a 58 40 73 65 63 74 69 |ng Files|.X@secti|
|000018a0| 6f 6e 20 45 78 61 6d 69 | 6e 69 6e 67 20 46 69 65 |on Exami|ning Fie|
|000018b0| 6c 64 73 0a 58 0a 58 40 | 63 69 6e 64 65 78 20 65 |lds.X.X@|cindex e|
|000018c0| 78 61 6d 69 6e 69 6e 67 | 20 66 69 65 6c 64 73 0a |xamining| fields.|
|000018d0| 58 40 63 69 6e 64 65 78 | 20 66 69 65 6c 64 73 0a |X@cindex| fields.|
|000018e0| 58 40 63 69 6e 64 65 78 | 20 61 63 63 65 73 73 69 |X@cindex| accessi|
|000018f0| 6e 67 20 66 69 65 6c 64 | 73 0a 58 57 68 65 6e 20 |ng field|s.XWhen |
|00001900| 40 63 6f 64 65 7b 61 77 | 6b 7d 20 72 65 61 64 73 |@code{aw|k} reads|
|00001910| 20 61 6e 20 69 6e 70 75 | 74 20 72 65 63 6f 72 64 | an inpu|t record|
|00001920| 2c 20 74 68 65 20 72 65 | 63 6f 72 64 20 69 73 0a |, the re|cord is.|
|00001930| 58 61 75 74 6f 6d 61 74 | 69 63 61 6c 6c 79 20 73 |Xautomat|ically s|
|00001940| 65 70 61 72 61 74 65 64 | 20 6f 72 20 40 64 66 6e |eparated| or @dfn|
|00001950| 7b 70 61 72 73 65 64 7d | 20 62 79 20 74 68 65 20 |{parsed}| by the |
|00001960| 69 6e 74 65 72 70 72 65 | 74 65 72 20 69 6e 74 6f |interpre|ter into|
|00001970| 20 70 69 65 63 65 73 0a | 58 63 61 6c 6c 65 64 20 | pieces.|Xcalled |
|00001980| 40 64 66 6e 7b 66 69 65 | 6c 64 73 7d 2e 20 20 42 |@dfn{fie|lds}. B|
|00001990| 79 20 64 65 66 61 75 6c | 74 2c 20 66 69 65 6c 64 |y defaul|t, field|
|000019a0| 73 20 61 72 65 20 73 65 | 70 61 72 61 74 65 64 20 |s are se|parated |
|000019b0| 62 79 20 77 68 69 74 65 | 73 70 61 63 65 2c 0a 58 |by white|space,.X|
|000019c0| 6c 69 6b 65 20 77 6f 72 | 64 73 20 69 6e 20 61 20 |like wor|ds in a |
|000019d0| 6c 69 6e 65 2e 0a 58 57 | 68 69 74 65 73 70 61 63 |line..XW|hitespac|
|000019e0| 65 20 69 6e 20 40 63 6f | 64 65 7b 61 77 6b 7d 20 |e in @co|de{awk} |
|000019f0| 6d 65 61 6e 73 20 61 6e | 79 20 73 74 72 69 6e 67 |means an|y string|
|00001a00| 20 6f 66 20 6f 6e 65 20 | 6f 72 20 6d 6f 72 65 20 | of one |or more |
|00001a10| 73 70 61 63 65 73 20 61 | 6e 64 2f 6f 72 0a 58 74 |spaces a|nd/or.Xt|
|00001a20| 61 62 73 3b 20 6f 74 68 | 65 72 20 63 68 61 72 61 |abs; oth|er chara|
|00001a30| 63 74 65 72 73 20 73 75 | 63 68 20 61 73 20 6e 65 |cters su|ch as ne|
|00001a40| 77 6c 69 6e 65 2c 20 66 | 6f 72 6d 66 65 65 64 2c |wline, f|ormfeed,|
|00001a50| 20 61 6e 64 20 73 6f 20 | 6f 6e 2c 20 74 68 61 74 | and so |on, that|
|00001a60| 20 61 72 65 0a 58 63 6f | 6e 73 69 64 65 72 65 64 | are.Xco|nsidered|
|00001a70| 20 77 68 69 74 65 73 70 | 61 63 65 20 62 79 20 6f | whitesp|ace by o|
|00001a80| 74 68 65 72 20 6c 61 6e | 67 75 61 67 65 73 20 61 |ther lan|guages a|
|00001a90| 72 65 20 40 65 6d 70 68 | 7b 6e 6f 74 7d 20 63 6f |re @emph|{not} co|
|00001aa0| 6e 73 69 64 65 72 65 64 | 0a 58 77 68 69 74 65 73 |nsidered|.Xwhites|
|00001ab0| 70 61 63 65 20 62 79 20 | 40 63 6f 64 65 7b 61 77 |pace by |@code{aw|
|00001ac0| 6b 7d 2e 0a 58 0a 58 54 | 68 65 20 70 75 72 70 6f |k}..X.XT|he purpo|
|00001ad0| 73 65 20 6f 66 20 66 69 | 65 6c 64 73 20 69 73 20 |se of fi|elds is |
|00001ae0| 74 6f 20 6d 61 6b 65 20 | 69 74 20 6d 6f 72 65 20 |to make |it more |
|00001af0| 63 6f 6e 76 65 6e 69 65 | 6e 74 20 66 6f 72 20 79 |convenie|nt for y|
|00001b00| 6f 75 20 74 6f 20 72 65 | 66 65 72 20 74 6f 0a 58 |ou to re|fer to.X|
|00001b10| 74 68 65 73 65 20 70 69 | 65 63 65 73 20 6f 66 20 |these pi|eces of |
|00001b20| 74 68 65 20 72 65 63 6f | 72 64 2e 20 20 59 6f 75 |the reco|rd. You|
|00001b30| 20 64 6f 6e 27 74 20 68 | 61 76 65 20 74 6f 20 75 | don't h|ave to u|
|00001b40| 73 65 20 74 68 65 6d 2d | 2d 2d 79 6f 75 20 63 61 |se them-|--you ca|
|00001b50| 6e 0a 58 6f 70 65 72 61 | 74 65 20 6f 6e 20 74 68 |n.Xopera|te on th|
|00001b60| 65 20 77 68 6f 6c 65 20 | 72 65 63 6f 72 64 20 69 |e whole |record i|
|00001b70| 66 20 79 6f 75 20 77 69 | 73 68 2d 2d 2d 62 75 74 |f you wi|sh---but|
|00001b80| 20 66 69 65 6c 64 73 20 | 61 72 65 20 77 68 61 74 | fields |are what|
|00001b90| 20 6d 61 6b 65 0a 58 73 | 69 6d 70 6c 65 20 40 63 | make.Xs|imple @c|
|00001ba0| 6f 64 65 7b 61 77 6b 7d | 20 70 72 6f 67 72 61 6d |ode{awk}| program|
|00001bb0| 73 20 73 6f 20 70 6f 77 | 65 72 66 75 6c 2e 0a 58 |s so pow|erful..X|
|00001bc0| 0a 58 40 63 69 6e 64 65 | 78 20 40 63 6f 64 65 7b |.X@cinde|x @code{|
|00001bd0| 24 7d 20 28 66 69 65 6c | 64 20 6f 70 65 72 61 74 |$} (fiel|d operat|
|00001be0| 6f 72 29 0a 58 40 63 69 | 6e 64 65 78 20 6f 70 65 |or).X@ci|ndex ope|
|00001bf0| 72 61 74 6f 72 73 2c 20 | 40 63 6f 64 65 7b 24 7d |rators, |@code{$}|
|00001c00| 0a 58 54 6f 20 72 65 66 | 65 72 20 74 6f 20 61 20 |.XTo ref|er to a |
|00001c10| 66 69 65 6c 64 20 69 6e | 20 61 6e 20 40 63 6f 64 |field in| an @cod|
|00001c20| 65 7b 61 77 6b 7d 20 70 | 72 6f 67 72 61 6d 2c 20 |e{awk} p|rogram, |
|00001c30| 79 6f 75 20 75 73 65 20 | 61 20 64 6f 6c 6c 61 72 |you use |a dollar|
|00001c40| 2d 73 69 67 6e 2c 0a 58 | 40 73 61 6d 70 7b 24 7d |-sign,.X|@samp{$}|
|00001c50| 2c 20 66 6f 6c 6c 6f 77 | 65 64 20 62 79 20 74 68 |, follow|ed by th|
|00001c60| 65 20 6e 75 6d 62 65 72 | 20 6f 66 20 74 68 65 20 |e number| of the |
|00001c70| 66 69 65 6c 64 20 79 6f | 75 20 77 61 6e 74 2e 20 |field yo|u want. |
|00001c80| 20 54 68 75 73 2c 20 40 | 63 6f 64 65 7b 24 31 7d | Thus, @|code{$1}|
|00001c90| 0a 58 72 65 66 65 72 73 | 20 74 6f 20 74 68 65 20 |.Xrefers| to the |
|00001ca0| 66 69 72 73 74 20 66 69 | 65 6c 64 2c 20 40 63 6f |first fi|eld, @co|
|00001cb0| 64 65 7b 24 32 7d 20 74 | 6f 20 74 68 65 20 73 65 |de{$2} t|o the se|
|00001cc0| 63 6f 6e 64 2c 20 61 6e | 64 20 73 6f 20 6f 6e 2e |cond, an|d so on.|
|00001cd0| 20 20 46 6f 72 0a 58 65 | 78 61 6d 70 6c 65 2c 20 | For.Xe|xample, |
|00001ce0| 73 75 70 70 6f 73 65 20 | 74 68 65 20 66 6f 6c 6c |suppose |the foll|
|00001cf0| 6f 77 69 6e 67 20 69 73 | 20 61 20 6c 69 6e 65 20 |owing is| a line |
|00001d00| 6f 66 20 69 6e 70 75 74 | 3a 40 72 65 66 69 6c 6c |of input|:@refill|
|00001d10| 0a 58 0a 58 40 65 78 61 | 6d 70 6c 65 0a 58 54 68 |.X.X@exa|mple.XTh|
|00001d20| 69 73 20 73 65 65 6d 73 | 20 6c 69 6b 65 20 61 20 |is seems| like a |
|00001d30| 70 72 65 74 74 79 20 6e | 69 63 65 20 65 78 61 6d |pretty n|ice exam|
|00001d40| 70 6c 65 2e 0a 58 40 65 | 6e 64 20 65 78 61 6d 70 |ple..X@e|nd examp|
|00001d50| 6c 65 0a 58 0a 58 40 6e | 6f 69 6e 64 65 6e 74 0a |le.X.X@n|oindent.|
|00001d60| 58 48 65 72 65 20 74 68 | 65 20 66 69 72 73 74 20 |XHere th|e first |
|00001d70| 66 69 65 6c 64 2c 20 6f | 72 20 40 63 6f 64 65 7b |field, o|r @code{|
|00001d80| 24 31 7d 2c 20 69 73 20 | 40 73 61 6d 70 7b 54 68 |$1}, is |@samp{Th|
|00001d90| 69 73 7d 3b 20 74 68 65 | 20 73 65 63 6f 6e 64 20 |is}; the| second |
|00001da0| 66 69 65 6c 64 2c 20 6f | 72 0a 58 40 63 6f 64 65 |field, o|r.X@code|
|00001db0| 7b 24 32 7d 2c 20 69 73 | 20 40 73 61 6d 70 7b 73 |{$2}, is| @samp{s|
|00001dc0| 65 65 6d 73 7d 3b 20 61 | 6e 64 20 73 6f 20 6f 6e |eems}; a|nd so on|
|00001dd0| 2e 20 20 4e 6f 74 65 20 | 74 68 61 74 20 74 68 65 |. Note |that the|
|00001de0| 20 6c 61 73 74 20 66 69 | 65 6c 64 2c 0a 58 40 63 | last fi|eld,.X@c|
|00001df0| 6f 64 65 7b 24 37 7d 2c | 20 69 73 20 40 73 61 6d |ode{$7},| is @sam|
|00001e00| 70 7b 65 78 61 6d 70 6c | 65 2e 7d 2e 20 20 42 65 |p{exampl|e.}. Be|
|00001e10| 63 61 75 73 65 20 74 68 | 65 72 65 20 69 73 20 6e |cause th|ere is n|
|00001e20| 6f 20 73 70 61 63 65 20 | 62 65 74 77 65 65 6e 20 |o space |between |
|00001e30| 74 68 65 0a 58 40 73 61 | 6d 70 7b 65 7d 20 61 6e |the.X@sa|mp{e} an|
|00001e40| 64 20 74 68 65 20 40 73 | 61 6d 70 7b 2e 7d 2c 20 |d the @s|amp{.}, |
|00001e50| 74 68 65 20 70 65 72 69 | 6f 64 20 69 73 20 63 6f |the peri|od is co|
|00001e60| 6e 73 69 64 65 72 65 64 | 20 70 61 72 74 20 6f 66 |nsidered| part of|
|00001e70| 20 74 68 65 20 73 65 76 | 65 6e 74 68 0a 58 66 69 | the sev|enth.Xfi|
|00001e80| 65 6c 64 2e 40 72 65 66 | 69 6c 6c 0a 58 0a 58 4e |eld.@ref|ill.X.XN|
|00001e90| 6f 20 6d 61 74 74 65 72 | 20 68 6f 77 20 6d 61 6e |o matter| how man|
|00001ea0| 79 20 66 69 65 6c 64 73 | 20 74 68 65 72 65 20 61 |y fields| there a|
|00001eb0| 72 65 2c 20 74 68 65 20 | 6c 61 73 74 20 66 69 65 |re, the |last fie|
|00001ec0| 6c 64 20 69 6e 20 61 20 | 72 65 63 6f 72 64 20 63 |ld in a |record c|
|00001ed0| 61 6e 20 62 65 0a 58 72 | 65 70 72 65 73 65 6e 74 |an be.Xr|epresent|
|00001ee0| 65 64 20 62 79 20 40 63 | 6f 64 65 7b 24 4e 46 7d |ed by @c|ode{$NF}|
|00001ef0| 2e 20 20 53 6f 2c 20 69 | 6e 20 74 68 65 20 65 78 |. So, i|n the ex|
|00001f00| 61 6d 70 6c 65 20 61 62 | 6f 76 65 2c 20 40 63 6f |ample ab|ove, @co|
|00001f10| 64 65 7b 24 4e 46 7d 20 | 77 6f 75 6c 64 0a 58 62 |de{$NF} |would.Xb|
|00001f20| 65 20 74 68 65 20 73 61 | 6d 65 20 61 73 20 40 63 |e the sa|me as @c|
|00001f30| 6f 64 65 7b 24 37 7d 2c | 20 77 68 69 63 68 20 69 |ode{$7},| which i|
|00001f40| 73 20 40 73 61 6d 70 7b | 65 78 61 6d 70 6c 65 2e |s @samp{|example.|
|00001f50| 7d 2e 20 20 57 68 79 20 | 74 68 69 73 20 77 6f 72 |}. Why |this wor|
|00001f60| 6b 73 20 69 73 0a 58 65 | 78 70 6c 61 69 6e 65 64 |ks is.Xe|xplained|
|00001f70| 20 62 65 6c 6f 77 20 28 | 40 70 78 72 65 66 7b 4e | below (|@pxref{N|
|00001f80| 6f 6e 2d 43 6f 6e 73 74 | 61 6e 74 20 46 69 65 6c |on-Const|ant Fiel|
|00001f90| 64 73 7d 29 2e 20 20 49 | 66 20 79 6f 75 20 74 72 |ds}). I|f you tr|
|00001fa0| 79 20 74 6f 20 72 65 66 | 65 72 20 74 6f 20 61 0a |y to ref|er to a.|
|00001fb0| 58 66 69 65 6c 64 20 62 | 65 79 6f 6e 64 20 74 68 |Xfield b|eyond th|
|00001fc0| 65 20 6c 61 73 74 20 6f | 6e 65 2c 20 73 75 63 68 |e last o|ne, such|
|00001fd0| 20 61 73 20 40 63 6f 64 | 65 7b 24 38 7d 20 77 68 | as @cod|e{$8} wh|
|00001fe0| 65 6e 20 74 68 65 20 72 | 65 63 6f 72 64 20 68 61 |en the r|ecord ha|
|00001ff0| 73 20 6f 6e 6c 79 20 37 | 0a 58 66 69 65 6c 64 73 |s only 7|.Xfields|
|00002000| 2c 20 79 6f 75 20 67 65 | 74 20 74 68 65 20 65 6d |, you ge|t the em|
|00002010| 70 74 79 20 73 74 72 69 | 6e 67 2e 0a 58 0a 58 40 |pty stri|ng..X.X@|
|00002020| 76 69 6e 64 65 78 20 4e | 46 0a 58 40 63 69 6e 64 |vindex N|F.X@cind|
|00002030| 65 78 20 6e 75 6d 62 65 | 72 20 6f 66 20 66 69 65 |ex numbe|r of fie|
|00002040| 6c 64 73 2c 20 40 63 6f | 64 65 7b 4e 46 7d 0a 58 |lds, @co|de{NF}.X|
|00002050| 50 6c 61 69 6e 20 40 63 | 6f 64 65 7b 4e 46 7d 2c |Plain @c|ode{NF},|
|00002060| 20 77 69 74 68 20 6e 6f | 20 40 73 61 6d 70 7b 24 | with no| @samp{$|
|00002070| 7d 2c 20 69 73 20 61 20 | 62 75 69 6c 74 2d 69 6e |}, is a |built-in|
|00002080| 20 76 61 72 69 61 62 6c | 65 20 77 68 6f 73 65 20 | variabl|e whose |
|00002090| 76 61 6c 75 65 0a 58 69 | 73 20 74 68 65 20 6e 75 |value.Xi|s the nu|
|000020a0| 6d 62 65 72 20 6f 66 20 | 66 69 65 6c 64 73 20 69 |mber of |fields i|
|000020b0| 6e 20 74 68 65 20 63 75 | 72 72 65 6e 74 20 72 65 |n the cu|rrent re|
|000020c0| 63 6f 72 64 2e 0a 58 0a | 58 40 63 6f 64 65 7b 24 |cord..X.|X@code{$|
|000020d0| 30 7d 2c 20 77 68 69 63 | 68 20 6c 6f 6f 6b 73 20 |0}, whic|h looks |
|000020e0| 6c 69 6b 65 20 61 6e 20 | 61 74 74 65 6d 70 74 20 |like an |attempt |
|000020f0| 74 6f 20 72 65 66 65 72 | 20 74 6f 20 74 68 65 20 |to refer| to the |
|00002100| 7a 65 72 6f 74 68 20 66 | 69 65 6c 64 2c 20 69 73 |zeroth f|ield, is|
|00002110| 0a 58 61 20 73 70 65 63 | 69 61 6c 20 63 61 73 65 |.Xa spec|ial case|
|00002120| 3a 20 69 74 20 72 65 70 | 72 65 73 65 6e 74 73 20 |: it rep|resents |
|00002130| 74 68 65 20 77 68 6f 6c | 65 20 69 6e 70 75 74 20 |the whol|e input |
|00002140| 72 65 63 6f 72 64 2e 20 | 20 54 68 69 73 20 69 73 |record. | This is|
|00002150| 20 77 68 61 74 20 79 6f | 75 0a 58 77 6f 75 6c 64 | what yo|u.Xwould|
|00002160| 20 75 73 65 20 77 68 65 | 6e 20 79 6f 75 20 61 72 | use whe|n you ar|
|00002170| 65 6e 27 74 20 69 6e 74 | 65 72 65 73 74 65 64 20 |en't int|erested |
|00002180| 69 6e 20 66 69 65 6c 64 | 73 2e 0a 58 0a 58 48 65 |in field|s..X.XHe|
|00002190| 72 65 20 61 72 65 20 73 | 6f 6d 65 20 6d 6f 72 65 |re are s|ome more|
|000021a0| 20 65 78 61 6d 70 6c 65 | 73 3a 0a 58 0a 58 40 65 | example|s:.X.X@e|
|000021b0| 78 61 6d 70 6c 65 0a 58 | 61 77 6b 20 27 24 31 20 |xample.X|awk '$1 |
|000021c0| 7e 20 2f 66 6f 6f 2f 20 | 40 7b 20 70 72 69 6e 74 |~ /foo/ |@{ print|
|000021d0| 20 24 30 20 40 7d 27 20 | 42 42 53 2d 6c 69 73 74 | $0 @}' |BBS-list|
|000021e0| 0a 58 40 65 6e 64 20 65 | 78 61 6d 70 6c 65 0a 58 |.X@end e|xample.X|
|000021f0| 0a 58 40 6e 6f 69 6e 64 | 65 6e 74 0a 58 54 68 69 |.X@noind|ent.XThi|
|00002200| 73 20 65 78 61 6d 70 6c | 65 20 70 72 69 6e 74 73 |s exampl|e prints|
|00002210| 20 65 61 63 68 20 72 65 | 63 6f 72 64 20 69 6e 20 | each re|cord in |
|00002220| 74 68 65 20 66 69 6c 65 | 20 40 66 69 6c 65 7b 42 |the file| @file{B|
|00002230| 42 53 2d 6c 69 73 74 7d | 20 77 68 6f 73 65 20 66 |BS-list}| whose f|
|00002240| 69 72 73 74 0a 58 66 69 | 65 6c 64 20 63 6f 6e 74 |irst.Xfi|eld cont|
|00002250| 61 69 6e 73 20 74 68 65 | 20 73 74 72 69 6e 67 20 |ains the| string |
|00002260| 40 73 61 6d 70 7b 66 6f | 6f 7d 2e 20 20 54 68 65 |@samp{fo|o}. The|
|00002270| 20 6f 70 65 72 61 74 6f | 72 20 40 73 61 6d 70 7b | operato|r @samp{|
|00002280| 7e 7d 20 69 73 20 63 61 | 6c 6c 65 64 20 61 0a 58 |~} is ca|lled a.X|
|00002290| 40 64 66 6e 7b 6d 61 74 | 63 68 69 6e 67 20 6f 70 |@dfn{mat|ching op|
|000022a0| 65 72 61 74 6f 72 7d 20 | 28 40 70 78 72 65 66 7b |erator} |(@pxref{|
|000022b0| 43 6f 6d 70 61 72 69 73 | 6f 6e 20 4f 70 73 7d 29 |Comparis|on Ops})|
|000022c0| 3b 20 69 74 20 74 65 73 | 74 73 20 77 68 65 74 68 |; it tes|ts wheth|
|000022d0| 65 72 20 61 0a 58 73 74 | 72 69 6e 67 20 28 68 65 |er a.Xst|ring (he|
|000022e0| 72 65 2c 20 74 68 65 20 | 66 69 65 6c 64 20 40 63 |re, the |field @c|
|000022f0| 6f 64 65 7b 24 31 7d 29 | 20 63 6f 6e 74 61 69 6e |ode{$1})| contain|
|00002300| 73 20 61 20 6d 61 74 63 | 68 20 66 6f 72 20 61 20 |s a matc|h for a |
|00002310| 67 69 76 65 6e 20 72 65 | 67 75 6c 61 72 0a 58 65 |given re|gular.Xe|
|00002320| 78 70 72 65 73 73 69 6f | 6e 2e 40 72 65 66 69 6c |xpressio|n.@refil|
|00002330| 6c 0a 58 0a 58 42 79 20 | 63 6f 6e 74 72 61 73 74 |l.X.XBy |contrast|
|00002340| 2c 20 74 68 65 20 66 6f | 6c 6c 6f 77 69 6e 67 20 |, the fo|llowing |
|00002350| 65 78 61 6d 70 6c 65 3a | 0a 58 0a 58 40 65 78 61 |example:|.X.X@exa|
|00002360| 6d 70 6c 65 0a 58 61 77 | 6b 20 27 2f 66 6f 6f 2f |mple.Xaw|k '/foo/|
|00002370| 20 40 7b 20 70 72 69 6e | 74 20 24 31 2c 20 24 4e | @{ prin|t $1, $N|
|00002380| 46 20 40 7d 27 20 42 42 | 53 2d 6c 69 73 74 0a 58 |F @}' BB|S-list.X|
|00002390| 40 65 6e 64 20 65 78 61 | 6d 70 6c 65 0a 58 0a 58 |@end exa|mple.X.X|
|000023a0| 40 6e 6f 69 6e 64 65 6e | 74 0a 58 6c 6f 6f 6b 73 |@noinden|t.Xlooks|
|000023b0| 20 66 6f 72 20 40 73 61 | 6d 70 7b 66 6f 6f 7d 20 | for @sa|mp{foo} |
|000023c0| 69 6e 20 40 65 6d 70 68 | 7b 74 68 65 20 65 6e 74 |in @emph|{the ent|
|000023d0| 69 72 65 20 72 65 63 6f | 72 64 7d 20 61 6e 64 20 |ire reco|rd} and |
|000023e0| 70 72 69 6e 74 73 20 74 | 68 65 20 66 69 72 73 74 |prints t|he first|
|000023f0| 0a 58 66 69 65 6c 64 20 | 61 6e 64 20 74 68 65 20 |.Xfield |and the |
|00002400| 6c 61 73 74 20 66 69 65 | 6c 64 20 66 6f 72 20 65 |last fie|ld for e|
|00002410| 61 63 68 20 69 6e 70 75 | 74 20 72 65 63 6f 72 64 |ach inpu|t record|
|00002420| 20 63 6f 6e 74 61 69 6e | 69 6e 67 20 61 0a 58 6d | contain|ing a.Xm|
|00002430| 61 74 63 68 2e 40 72 65 | 66 69 6c 6c 0a 58 0a 58 |atch.@re|fill.X.X|
|00002440| 40 6e 6f 64 65 20 4e 6f | 6e 2d 43 6f 6e 73 74 61 |@node No|n-Consta|
|00002450| 6e 74 20 46 69 65 6c 64 | 73 2c 20 43 68 61 6e 67 |nt Field|s, Chang|
|00002460| 69 6e 67 20 46 69 65 6c | 64 73 2c 20 46 69 65 6c |ing Fiel|ds, Fiel|
|00002470| 64 73 2c 20 52 65 61 64 | 69 6e 67 20 46 69 6c 65 |ds, Read|ing File|
|00002480| 73 0a 58 40 73 65 63 74 | 69 6f 6e 20 4e 6f 6e 2d |s.X@sect|ion Non-|
|00002490| 63 6f 6e 73 74 61 6e 74 | 20 46 69 65 6c 64 20 4e |constant| Field N|
|000024a0| 75 6d 62 65 72 73 0a 58 | 0a 58 54 68 65 20 6e 75 |umbers.X|.XThe nu|
|000024b0| 6d 62 65 72 20 6f 66 20 | 61 20 66 69 65 6c 64 20 |mber of |a field |
|000024c0| 64 6f 65 73 20 6e 6f 74 | 20 6e 65 65 64 20 74 6f |does not| need to|
|000024d0| 20 62 65 20 61 20 63 6f | 6e 73 74 61 6e 74 2e 20 | be a co|nstant. |
|000024e0| 20 41 6e 79 20 65 78 70 | 72 65 73 73 69 6f 6e 20 | Any exp|ression |
|000024f0| 69 6e 0a 58 74 68 65 20 | 40 63 6f 64 65 7b 61 77 |in.Xthe |@code{aw|
|00002500| 6b 7d 20 6c 61 6e 67 75 | 61 67 65 20 63 61 6e 20 |k} langu|age can |
|00002510| 62 65 20 75 73 65 64 20 | 61 66 74 65 72 20 61 20 |be used |after a |
|00002520| 40 73 61 6d 70 7b 24 7d | 20 74 6f 20 72 65 66 65 |@samp{$}| to refe|
|00002530| 72 20 74 6f 20 61 0a 58 | 66 69 65 6c 64 2e 20 20 |r to a.X|field. |
|00002540| 54 68 65 20 76 61 6c 75 | 65 20 6f 66 20 74 68 65 |The valu|e of the|
|00002550| 20 65 78 70 72 65 73 73 | 69 6f 6e 20 73 70 65 63 | express|ion spec|
|00002560| 69 66 69 65 73 20 74 68 | 65 20 66 69 65 6c 64 20 |ifies th|e field |
|00002570| 6e 75 6d 62 65 72 2e 20 | 20 49 66 20 74 68 65 0a |number. | If the.|
|00002580| 58 76 61 6c 75 65 20 69 | 73 20 61 20 73 74 72 69 |Xvalue i|s a stri|
|00002590| 6e 67 2c 20 72 61 74 68 | 65 72 20 74 68 61 6e 20 |ng, rath|er than |
|000025a0| 61 20 6e 75 6d 62 65 72 | 2c 20 69 74 20 69 73 20 |a number|, it is |
|000025b0| 63 6f 6e 76 65 72 74 65 | 64 20 74 6f 20 61 20 6e |converte|d to a n|
|000025c0| 75 6d 62 65 72 2e 0a 58 | 43 6f 6e 73 69 64 65 72 |umber..X|Consider|
|000025d0| 20 74 68 69 73 20 65 78 | 61 6d 70 6c 65 3a 40 72 | this ex|ample:@r|
|000025e0| 65 66 69 6c 6c 0a 58 0a | 58 40 65 78 61 6d 70 6c |efill.X.|X@exampl|
|000025f0| 65 0a 58 61 77 6b 20 27 | 40 7b 20 70 72 69 6e 74 |e.Xawk '|@{ print|
|00002600| 20 24 4e 52 20 40 7d 27 | 0a 58 40 65 6e 64 20 65 | $NR @}'|.X@end e|
|00002610| 78 61 6d 70 6c 65 0a 58 | 0a 58 40 6e 6f 69 6e 64 |xample.X|.X@noind|
|00002620| 65 6e 74 0a 58 52 65 63 | 61 6c 6c 20 74 68 61 74 |ent.XRec|all that|
|00002630| 20 40 63 6f 64 65 7b 4e | 52 7d 20 69 73 20 74 68 | @code{N|R} is th|
|00002640| 65 20 6e 75 6d 62 65 72 | 20 6f 66 20 72 65 63 6f |e number| of reco|
|00002650| 72 64 73 20 72 65 61 64 | 20 73 6f 20 66 61 72 3a |rds read| so far:|
|00002660| 20 31 20 69 6e 20 74 68 | 65 0a 58 66 69 72 73 74 | 1 in th|e.Xfirst|
|00002670| 20 72 65 63 6f 72 64 2c | 20 32 20 69 6e 20 74 68 | record,| 2 in th|
|00002680| 65 20 73 65 63 6f 6e 64 | 2c 20 65 74 63 2e 20 20 |e second|, etc. |
|00002690| 53 6f 20 74 68 69 73 20 | 65 78 61 6d 70 6c 65 20 |So this |example |
|000026a0| 70 72 69 6e 74 73 20 74 | 68 65 20 66 69 72 73 74 |prints t|he first|
|000026b0| 0a 58 66 69 65 6c 64 20 | 6f 66 20 74 68 65 20 66 |.Xfield |of the f|
|000026c0| 69 72 73 74 20 72 65 63 | 6f 72 64 2c 20 74 68 65 |irst rec|ord, the|
|000026d0| 20 73 65 63 6f 6e 64 20 | 66 69 65 6c 64 20 6f 66 | second |field of|
|000026e0| 20 74 68 65 20 73 65 63 | 6f 6e 64 20 72 65 63 6f | the sec|ond reco|
|000026f0| 72 64 2c 20 61 6e 64 20 | 73 6f 0a 58 6f 6e 2e 20 |rd, and |so.Xon. |
|00002700| 20 46 6f 72 20 74 68 65 | 20 74 77 65 6e 74 69 65 | For the| twentie|
|00002710| 74 68 20 72 65 63 6f 72 | 64 2c 20 66 69 65 6c 64 |th recor|d, field|
|00002720| 20 6e 75 6d 62 65 72 20 | 32 30 20 69 73 20 70 72 | number |20 is pr|
|00002730| 69 6e 74 65 64 3b 20 6d | 6f 73 74 20 6c 69 6b 65 |inted; m|ost like|
|00002740| 6c 79 2c 0a 58 74 68 65 | 20 72 65 63 6f 72 64 20 |ly,.Xthe| record |
|00002750| 68 61 73 20 66 65 77 65 | 72 20 74 68 61 6e 20 32 |has fewe|r than 2|
|00002760| 30 20 66 69 65 6c 64 73 | 2c 20 73 6f 20 74 68 69 |0 fields|, so thi|
|00002770| 73 20 70 72 69 6e 74 73 | 20 61 20 62 6c 61 6e 6b |s prints| a blank|
|00002780| 20 6c 69 6e 65 2e 0a 58 | 0a 58 48 65 72 65 20 69 | line..X|.XHere i|
|00002790| 73 20 61 6e 6f 74 68 65 | 72 20 65 78 61 6d 70 6c |s anothe|r exampl|
|000027a0| 65 20 6f 66 20 75 73 69 | 6e 67 20 65 78 70 72 65 |e of usi|ng expre|
|000027b0| 73 73 69 6f 6e 73 20 61 | 73 20 66 69 65 6c 64 20 |ssions a|s field |
|000027c0| 6e 75 6d 62 65 72 73 3a | 0a 58 0a 58 40 65 78 61 |numbers:|.X.X@exa|
|000027d0| 6d 70 6c 65 0a 58 61 77 | 6b 20 27 40 7b 20 70 72 |mple.Xaw|k '@{ pr|
|000027e0| 69 6e 74 20 24 28 32 2a | 32 29 20 40 7d 27 20 42 |int $(2*|2) @}' B|
|000027f0| 42 53 2d 6c 69 73 74 0a | 58 40 65 6e 64 20 65 78 |BS-list.|X@end ex|
|00002800| 61 6d 70 6c 65 0a 58 0a | 58 54 68 65 20 40 63 6f |ample.X.|XThe @co|
|00002810| 64 65 7b 61 77 6b 7d 20 | 6c 61 6e 67 75 61 67 65 |de{awk} |language|
|00002820| 20 6d 75 73 74 20 65 76 | 61 6c 75 61 74 65 20 74 | must ev|aluate t|
|00002830| 68 65 20 65 78 70 72 65 | 73 73 69 6f 6e 20 40 63 |he expre|ssion @c|
|00002840| 6f 64 65 7b 28 32 2a 32 | 29 7d 20 61 6e 64 20 75 |ode{(2*2|)} and u|
|00002850| 73 65 0a 58 69 74 73 20 | 76 61 6c 75 65 20 61 73 |se.Xits |value as|
|00002860| 20 74 68 65 20 6e 75 6d | 62 65 72 20 6f 66 20 74 | the num|ber of t|
|00002870| 68 65 20 66 69 65 6c 64 | 20 74 6f 20 70 72 69 6e |he field| to prin|
|00002880| 74 2e 20 20 54 68 65 20 | 40 73 61 6d 70 7b 2a 7d |t. The |@samp{*}|
|00002890| 20 73 69 67 6e 0a 58 72 | 65 70 72 65 73 65 6e 74 | sign.Xr|epresent|
|000028a0| 73 20 6d 75 6c 74 69 70 | 6c 69 63 61 74 69 6f 6e |s multip|lication|
|000028b0| 2c 20 73 6f 20 74 68 65 | 20 65 78 70 72 65 73 73 |, so the| express|
|000028c0| 69 6f 6e 20 40 63 6f 64 | 65 7b 32 2a 32 7d 20 65 |ion @cod|e{2*2} e|
|000028d0| 76 61 6c 75 61 74 65 73 | 20 74 6f 20 34 2e 0a 58 |valuates| to 4..X|
|000028e0| 54 68 65 20 70 61 72 65 | 6e 74 68 65 73 65 73 20 |The pare|ntheses |
|000028f0| 61 72 65 20 75 73 65 64 | 20 73 6f 20 74 68 61 74 |are used| so that|
|00002900| 20 74 68 65 20 6d 75 6c | 74 69 70 6c 69 63 61 74 | the mul|tiplicat|
|00002910| 69 6f 6e 20 69 73 20 64 | 6f 6e 65 20 62 65 66 6f |ion is d|one befo|
|00002920| 72 65 20 74 68 65 0a 58 | 40 73 61 6d 70 7b 24 7d |re the.X|@samp{$}|
|00002930| 20 6f 70 65 72 61 74 69 | 6f 6e 3b 20 74 68 65 79 | operati|on; they|
|00002940| 20 61 72 65 20 6e 65 63 | 65 73 73 61 72 79 20 77 | are nec|essary w|
|00002950| 68 65 6e 65 76 65 72 20 | 74 68 65 72 65 20 69 73 |henever |there is|
|00002960| 20 61 20 62 69 6e 61 72 | 79 0a 58 6f 70 65 72 61 | a binar|y.Xopera|
|00002970| 74 6f 72 20 69 6e 20 74 | 68 65 20 66 69 65 6c 64 |tor in t|he field|
|00002980| 2d 6e 75 6d 62 65 72 20 | 65 78 70 72 65 73 73 69 |-number |expressi|
|00002990| 6f 6e 2e 20 20 54 68 69 | 73 20 65 78 61 6d 70 6c |on. Thi|s exampl|
|000029a0| 65 2c 20 74 68 65 6e 2c | 20 70 72 69 6e 74 73 20 |e, then,| prints |
|000029b0| 74 68 65 0a 58 68 6f 75 | 72 73 20 6f 66 20 6f 70 |the.Xhou|rs of op|
|000029c0| 65 72 61 74 69 6f 6e 20 | 28 74 68 65 20 66 6f 75 |eration |(the fou|
|000029d0| 72 74 68 20 66 69 65 6c | 64 29 20 66 6f 72 20 65 |rth fiel|d) for e|
|000029e0| 76 65 72 79 20 6c 69 6e | 65 20 6f 66 20 74 68 65 |very lin|e of the|
|000029f0| 20 66 69 6c 65 0a 58 40 | 66 69 6c 65 7b 42 42 53 | file.X@|file{BBS|
|00002a00| 2d 6c 69 73 74 7d 2e 40 | 72 65 66 69 6c 6c 0a 58 |-list}.@|refill.X|
|00002a10| 0a 58 49 66 20 74 68 65 | 20 66 69 65 6c 64 20 6e |.XIf the| field n|
|00002a20| 75 6d 62 65 72 20 79 6f | 75 20 63 6f 6d 70 75 74 |umber yo|u comput|
|00002a30| 65 20 69 73 20 7a 65 72 | 6f 2c 20 79 6f 75 20 67 |e is zer|o, you g|
|00002a40| 65 74 20 74 68 65 20 65 | 6e 74 69 72 65 20 72 65 |et the e|ntire re|
|00002a50| 63 6f 72 64 2e 0a 58 54 | 68 75 73 2c 20 40 63 6f |cord..XT|hus, @co|
|00002a60| 64 65 7b 24 28 32 2d 32 | 29 7d 20 68 61 73 20 74 |de{$(2-2|)} has t|
|00002a70| 68 65 20 73 61 6d 65 20 | 76 61 6c 75 65 20 61 73 |he same |value as|
|00002a80| 20 40 63 6f 64 65 7b 24 | 30 7d 2e 20 20 4e 65 67 | @code{$|0}. Neg|
|00002a90| 61 74 69 76 65 20 66 69 | 65 6c 64 0a 58 6e 75 6d |ative fi|eld.Xnum|
|00002aa0| 62 65 72 73 20 61 72 65 | 20 6e 6f 74 20 61 6c 6c |bers are| not all|
|00002ab0| 6f 77 65 64 2e 0a 58 0a | 58 54 68 65 20 6e 75 6d |owed..X.|XThe num|
|00002ac0| 62 65 72 20 6f 66 20 66 | 69 65 6c 64 73 20 69 6e |ber of f|ields in|
|00002ad0| 20 74 68 65 20 63 75 72 | 72 65 6e 74 20 72 65 63 | the cur|rent rec|
|00002ae0| 6f 72 64 20 69 73 20 73 | 74 6f 72 65 64 20 69 6e |ord is s|tored in|
|00002af0| 20 74 68 65 20 62 75 69 | 6c 74 2d 69 6e 0a 58 76 | the bui|lt-in.Xv|
|00002b00| 61 72 69 61 62 6c 65 20 | 40 63 6f 64 65 7b 4e 46 |ariable |@code{NF|
|00002b10| 7d 20 28 40 70 78 72 65 | 66 7b 42 75 69 6c 74 2d |} (@pxre|f{Built-|
|00002b20| 69 6e 20 56 61 72 69 61 | 62 6c 65 73 7d 29 2e 20 |in Varia|bles}). |
|00002b30| 20 54 68 65 20 65 78 70 | 72 65 73 73 69 6f 6e 0a | The exp|ression.|
|00002b40| 58 40 63 6f 64 65 7b 24 | 4e 46 7d 20 69 73 20 6e |X@code{$|NF} is n|
|00002b50| 6f 74 20 61 20 73 70 65 | 63 69 61 6c 20 66 65 61 |ot a spe|cial fea|
|00002b60| 74 75 72 65 3a 20 69 74 | 20 69 73 20 74 68 65 20 |ture: it| is the |
|00002b70| 64 69 72 65 63 74 20 63 | 6f 6e 73 65 71 75 65 6e |direct c|onsequen|
|00002b80| 63 65 20 6f 66 0a 58 65 | 76 61 6c 75 61 74 69 6e |ce of.Xe|valuatin|
|00002b90| 67 20 40 63 6f 64 65 7b | 4e 46 7d 20 61 6e 64 20 |g @code{|NF} and |
|00002ba0| 75 73 69 6e 67 20 69 74 | 73 20 76 61 6c 75 65 20 |using it|s value |
|00002bb0| 61 73 20 61 20 66 69 65 | 6c 64 20 6e 75 6d 62 65 |as a fie|ld numbe|
|00002bc0| 72 2e 0a 58 0a 58 40 6e | 6f 64 65 20 43 68 61 6e |r..X.X@n|ode Chan|
|00002bd0| 67 69 6e 67 20 46 69 65 | 6c 64 73 2c 20 46 69 65 |ging Fie|lds, Fie|
|00002be0| 6c 64 20 53 65 70 61 72 | 61 74 6f 72 73 2c 20 4e |ld Separ|ators, N|
|00002bf0| 6f 6e 2d 43 6f 6e 73 74 | 61 6e 74 20 46 69 65 6c |on-Const|ant Fiel|
|00002c00| 64 73 2c 20 52 65 61 64 | 69 6e 67 20 46 69 6c 65 |ds, Read|ing File|
|00002c10| 73 0a 58 40 73 65 63 74 | 69 6f 6e 20 43 68 61 6e |s.X@sect|ion Chan|
|00002c20| 67 69 6e 67 20 74 68 65 | 20 43 6f 6e 74 65 6e 74 |ging the| Content|
|00002c30| 73 20 6f 66 20 61 20 46 | 69 65 6c 64 0a 58 0a 58 |s of a F|ield.X.X|
|00002c40| 40 63 69 6e 64 65 78 20 | 66 69 65 6c 64 2c 20 63 |@cindex |field, c|
|00002c50| 68 61 6e 67 69 6e 67 20 | 63 6f 6e 74 65 6e 74 73 |hanging |contents|
|00002c60| 20 6f 66 0a 58 40 63 69 | 6e 64 65 78 20 63 68 61 | of.X@ci|ndex cha|
|00002c70| 6e 67 69 6e 67 20 63 6f | 6e 74 65 6e 74 73 20 6f |nging co|ntents o|
|00002c80| 66 20 61 20 66 69 65 6c | 64 0a 58 40 63 69 6e 64 |f a fiel|d.X@cind|
|00002c90| 65 78 20 61 73 73 69 67 | 6e 6d 65 6e 74 20 74 6f |ex assig|nment to|
|00002ca0| 20 66 69 65 6c 64 73 0a | 58 59 6f 75 20 63 61 6e | fields.|XYou can|
|00002cb0| 20 63 68 61 6e 67 65 20 | 74 68 65 20 63 6f 6e 74 | change |the cont|
|00002cc0| 65 6e 74 73 20 6f 66 20 | 61 20 66 69 65 6c 64 20 |ents of |a field |
|00002cd0| 61 73 20 73 65 65 6e 20 | 62 79 20 40 63 6f 64 65 |as seen |by @code|
|00002ce0| 7b 61 77 6b 7d 20 77 69 | 74 68 69 6e 20 61 6e 0a |{awk} wi|thin an.|
|00002cf0| 58 40 63 6f 64 65 7b 61 | 77 6b 7d 20 70 72 6f 67 |X@code{a|wk} prog|
|00002d00| 72 61 6d 3b 20 74 68 69 | 73 20 63 68 61 6e 67 65 |ram; thi|s change|
|00002d10| 73 20 77 68 61 74 20 40 | 63 6f 64 65 7b 61 77 6b |s what @|code{awk|
|00002d20| 7d 20 70 65 72 63 65 69 | 76 65 73 20 61 73 20 74 |} percei|ves as t|
|00002d30| 68 65 0a 58 63 75 72 72 | 65 6e 74 20 69 6e 70 75 |he.Xcurr|ent inpu|
|00002d40| 74 20 72 65 63 6f 72 64 | 2e 20 20 28 54 68 65 20 |t record|. (The |
|00002d50| 61 63 74 75 61 6c 20 69 | 6e 70 75 74 20 69 73 20 |actual i|nput is |
|00002d60| 75 6e 74 6f 75 63 68 65 | 64 3a 20 40 63 6f 64 65 |untouche|d: @code|
|00002d70| 7b 61 77 6b 7d 20 6e 65 | 76 65 72 0a 58 6d 6f 64 |{awk} ne|ver.Xmod|
|00002d80| 69 66 69 65 73 20 74 68 | 65 20 69 6e 70 75 74 20 |ifies th|e input |
|00002d90| 66 69 6c 65 2e 29 0a 58 | 0a 58 4c 6f 6f 6b 20 61 |file.).X|.XLook a|
|00002da0| 74 20 74 68 69 73 20 65 | 78 61 6d 70 6c 65 3a 0a |t this e|xample:.|
|00002db0| 58 0a 58 40 65 78 61 6d | 70 6c 65 0a 58 61 77 6b |X.X@exam|ple.Xawk|
|00002dc0| 20 27 40 7b 20 24 33 20 | 3d 20 24 32 20 2d 20 31 | '@{ $3 |= $2 - 1|
|00002dd0| 30 3b 20 70 72 69 6e 74 | 20 24 32 2c 20 24 33 20 |0; print| $2, $3 |
|00002de0| 40 7d 27 20 69 6e 76 65 | 6e 74 6f 72 79 2d 73 68 |@}' inve|ntory-sh|
|00002df0| 69 70 70 65 64 0a 58 40 | 65 6e 64 20 65 78 61 6d |ipped.X@|end exam|
|00002e00| 70 6c 65 0a 58 0a 58 40 | 6e 6f 69 6e 64 65 6e 74 |ple.X.X@|noindent|
|00002e10| 0a 58 54 68 65 20 40 73 | 61 6d 70 7b 2d 7d 20 73 |.XThe @s|amp{-} s|
|00002e20| 69 67 6e 20 72 65 70 72 | 65 73 65 6e 74 73 20 73 |ign repr|esents s|
|00002e30| 75 62 74 72 61 63 74 69 | 6f 6e 2c 20 73 6f 20 74 |ubtracti|on, so t|
|00002e40| 68 69 73 20 70 72 6f 67 | 72 61 6d 20 72 65 61 73 |his prog|ram reas|
|00002e50| 73 69 67 6e 73 0a 58 66 | 69 65 6c 64 20 74 68 72 |signs.Xf|ield thr|
|00002e60| 65 65 2c 20 40 63 6f 64 | 65 7b 24 33 7d 2c 20 74 |ee, @cod|e{$3}, t|
|00002e70| 6f 20 62 65 20 74 68 65 | 20 76 61 6c 75 65 20 6f |o be the| value o|
|00002e80| 66 20 66 69 65 6c 64 20 | 74 77 6f 20 6d 69 6e 75 |f field |two minu|
|00002e90| 73 20 74 65 6e 2c 0a 58 | 40 63 6f 64 65 7b 24 32 |s ten,.X|@code{$2|
|00002ea0| 20 2d 20 31 30 7d 2e 20 | 20 28 40 78 72 65 66 7b | - 10}. | (@xref{|
|00002eb0| 41 72 69 74 68 6d 65 74 | 69 63 20 4f 70 73 7d 2e |Arithmet|ic Ops}.|
|00002ec0| 29 20 20 54 68 65 6e 20 | 66 69 65 6c 64 20 74 77 |) Then |field tw|
|00002ed0| 6f 2c 20 61 6e 64 20 74 | 68 65 0a 58 6e 65 77 20 |o, and t|he.Xnew |
|00002ee0| 76 61 6c 75 65 20 66 6f | 72 20 66 69 65 6c 64 20 |value fo|r field |
|00002ef0| 74 68 72 65 65 2c 20 61 | 72 65 20 70 72 69 6e 74 |three, a|re print|
|00002f00| 65 64 2e 20 20 0a 58 0a | 58 49 6e 20 6f 72 64 65 |ed. .X.|XIn orde|
|00002f10| 72 20 66 6f 72 20 74 68 | 69 73 20 74 6f 20 77 6f |r for th|is to wo|
|00002f20| 72 6b 2c 20 74 68 65 20 | 74 65 78 74 20 69 6e 20 |rk, the |text in |
|00002f30| 66 69 65 6c 64 20 40 63 | 6f 64 65 7b 24 32 7d 20 |field @c|ode{$2} |
|00002f40| 6d 75 73 74 20 6d 61 6b | 65 20 73 65 6e 73 65 0a |must mak|e sense.|
|00002f50| 58 61 73 20 61 20 6e 75 | 6d 62 65 72 3b 20 74 68 |Xas a nu|mber; th|
|00002f60| 65 20 73 74 72 69 6e 67 | 20 6f 66 20 63 68 61 72 |e string| of char|
|00002f70| 61 63 74 65 72 73 20 6d | 75 73 74 20 62 65 20 63 |acters m|ust be c|
|00002f80| 6f 6e 76 65 72 74 65 64 | 20 74 6f 20 61 20 6e 75 |onverted| to a nu|
|00002f90| 6d 62 65 72 20 69 6e 0a | 58 6f 72 64 65 72 20 66 |mber in.|Xorder f|
|00002fa0| 6f 72 20 74 68 65 20 63 | 6f 6d 70 75 74 65 72 20 |or the c|omputer |
|00002fb0| 74 6f 20 64 6f 20 61 72 | 69 74 68 6d 65 74 69 63 |to do ar|ithmetic|
|00002fc0| 20 6f 6e 20 69 74 2e 20 | 20 54 68 65 20 6e 75 6d | on it. | The num|
|00002fd0| 62 65 72 20 72 65 73 75 | 6c 74 69 6e 67 0a 58 66 |ber resu|lting.Xf|
|00002fe0| 72 6f 6d 20 74 68 65 20 | 73 75 62 74 72 61 63 74 |rom the |subtract|
|00002ff0| 69 6f 6e 20 69 73 20 63 | 6f 6e 76 65 72 74 65 64 |ion is c|onverted|
|00003000| 20 62 61 63 6b 20 74 6f | 20 61 20 73 74 72 69 6e | back to| a strin|
|00003010| 67 20 6f 66 20 63 68 61 | 72 61 63 74 65 72 73 20 |g of cha|racters |
|00003020| 77 68 69 63 68 0a 58 74 | 68 65 6e 20 62 65 63 6f |which.Xt|hen beco|
|00003030| 6d 65 73 20 66 69 65 6c | 64 20 74 68 72 65 65 2e |mes fiel|d three.|
|00003040| 20 20 40 78 72 65 66 7b | 43 6f 6e 76 65 72 73 69 | @xref{|Conversi|
|00003050| 6f 6e 7d 2e 0a 58 0a 58 | 57 68 65 6e 20 79 6f 75 |on}..X.X|When you|
|00003060| 20 63 68 61 6e 67 65 20 | 74 68 65 20 76 61 6c 75 | change |the valu|
|00003070| 65 20 6f 66 20 61 20 66 | 69 65 6c 64 20 28 61 73 |e of a f|ield (as|
|00003080| 20 70 65 72 63 65 69 76 | 65 64 20 62 79 20 40 63 | perceiv|ed by @c|
|00003090| 6f 64 65 7b 61 77 6b 7d | 29 2c 20 74 68 65 0a 58 |ode{awk}|), the.X|
|000030a0| 74 65 78 74 20 6f 66 20 | 74 68 65 20 69 6e 70 75 |text of |the inpu|
|000030b0| 74 20 72 65 63 6f 72 64 | 20 69 73 20 72 65 63 61 |t record| is reca|
|000030c0| 6c 63 75 6c 61 74 65 64 | 20 74 6f 20 63 6f 6e 74 |lculated| to cont|
|000030d0| 61 69 6e 20 74 68 65 20 | 6e 65 77 20 66 69 65 6c |ain the |new fiel|
|000030e0| 64 20 77 68 65 72 65 0a | 58 74 68 65 20 6f 6c 64 |d where.|Xthe old|
|000030f0| 20 6f 6e 65 20 77 61 73 | 2e 20 20 54 68 65 72 65 | one was|. There|
|00003100| 66 6f 72 65 2c 20 40 63 | 6f 64 65 7b 24 30 7d 20 |fore, @c|ode{$0} |
|00003110| 63 68 61 6e 67 65 73 20 | 74 6f 20 72 65 66 6c 65 |changes |to refle|
|00003120| 63 74 20 74 68 65 20 61 | 6c 74 65 72 65 64 0a 58 |ct the a|ltered.X|
|00003130| 66 69 65 6c 64 2e 20 20 | 54 68 75 73 2c 0a 58 0a |field. |Thus,.X.|
|00003140| 58 40 65 78 61 6d 70 6c | 65 0a 58 61 77 6b 20 27 |X@exampl|e.Xawk '|
|00003150| 40 7b 20 24 32 20 3d 20 | 24 32 20 2d 20 31 30 3b |@{ $2 = |$2 - 10;|
|00003160| 20 70 72 69 6e 74 20 24 | 30 20 40 7d 27 20 69 6e | print $|0 @}' in|
|00003170| 76 65 6e 74 6f 72 79 2d | 73 68 69 70 70 65 64 0a |ventory-|shipped.|
|00003180| 58 40 65 6e 64 20 65 78 | 61 6d 70 6c 65 0a 58 0a |X@end ex|ample.X.|
|00003190| 58 40 6e 6f 69 6e 64 65 | 6e 74 0a 58 70 72 69 6e |X@noinde|nt.Xprin|
|000031a0| 74 73 20 61 20 63 6f 70 | 79 20 6f 66 20 74 68 65 |ts a cop|y of the|
|000031b0| 20 69 6e 70 75 74 20 66 | 69 6c 65 2c 20 77 69 74 | input f|ile, wit|
|000031c0| 68 20 31 30 20 73 75 62 | 74 72 61 63 74 65 64 20 |h 10 sub|tracted |
|000031d0| 66 72 6f 6d 20 74 68 65 | 20 73 65 63 6f 6e 64 0a |from the| second.|
|000031e0| 58 66 69 65 6c 64 20 6f | 66 20 65 61 63 68 20 6c |Xfield o|f each l|
|000031f0| 69 6e 65 2e 0a 58 0a 58 | 59 6f 75 20 63 61 6e 20 |ine..X.X|You can |
|00003200| 61 6c 73 6f 20 61 73 73 | 69 67 6e 20 63 6f 6e 74 |also ass|ign cont|
|00003210| 65 6e 74 73 20 74 6f 20 | 66 69 65 6c 64 73 20 74 |ents to |fields t|
|00003220| 68 61 74 20 61 72 65 20 | 6f 75 74 20 6f 66 20 72 |hat are |out of r|
|00003230| 61 6e 67 65 2e 20 20 46 | 6f 72 0a 58 65 78 61 6d |ange. F|or.Xexam|
|00003240| 70 6c 65 3a 0a 58 0a 58 | 40 65 78 61 6d 70 6c 65 |ple:.X.X|@example|
|00003250| 0a 58 61 77 6b 20 27 40 | 7b 20 24 36 20 3d 20 28 |.Xawk '@|{ $6 = (|
|00003260| 24 35 20 2b 20 24 34 20 | 2b 20 24 33 20 2b 20 24 |$5 + $4 |+ $3 + $|
|00003270| 32 29 20 3b 20 70 72 69 | 6e 74 20 24 36 20 40 7d |2) ; pri|nt $6 @}|
|00003280| 27 20 69 6e 76 65 6e 74 | 6f 72 79 2d 73 68 69 70 |' invent|ory-ship|
|00003290| 70 65 64 0a 58 40 65 6e | 64 20 65 78 61 6d 70 6c |ped.X@en|d exampl|
|000032a0| 65 0a 58 0a 58 40 6e 6f | 69 6e 64 65 6e 74 0a 58 |e.X.X@no|indent.X|
|000032b0| 57 65 27 76 65 20 6a 75 | 73 74 20 63 72 65 61 74 |We've ju|st creat|
|000032c0| 65 64 20 40 63 6f 64 65 | 7b 24 36 7d 2c 20 77 68 |ed @code|{$6}, wh|
|000032d0| 6f 73 65 20 76 61 6c 75 | 65 20 69 73 20 74 68 65 |ose valu|e is the|
|000032e0| 20 73 75 6d 20 6f 66 20 | 66 69 65 6c 64 73 0a 58 | sum of |fields.X|
|000032f0| 40 63 6f 64 65 7b 24 32 | 7d 2c 20 40 63 6f 64 65 |@code{$2|}, @code|
|00003300| 7b 24 33 7d 2c 20 40 63 | 6f 64 65 7b 24 34 7d 2c |{$3}, @c|ode{$4},|
|00003310| 20 61 6e 64 20 40 63 6f | 64 65 7b 24 35 7d 2e 20 | and @co|de{$5}. |
|00003320| 20 54 68 65 20 40 73 61 | 6d 70 7b 2b 7d 20 73 69 | The @sa|mp{+} si|
|00003330| 67 6e 0a 58 72 65 70 72 | 65 73 65 6e 74 73 20 61 |gn.Xrepr|esents a|
|00003340| 64 64 69 74 69 6f 6e 2e | 20 20 46 6f 72 20 74 68 |ddition.| For th|
|00003350| 65 20 66 69 6c 65 20 40 | 66 69 6c 65 7b 69 6e 76 |e file @|file{inv|
|00003360| 65 6e 74 6f 72 79 2d 73 | 68 69 70 70 65 64 7d 2c |entory-s|hipped},|
|00003370| 20 40 63 6f 64 65 7b 24 | 36 7d 0a 58 72 65 70 72 | @code{$|6}.Xrepr|
|00003380| 65 73 65 6e 74 73 20 74 | 68 65 20 74 6f 74 61 6c |esents t|he total|
|00003390| 20 6e 75 6d 62 65 72 20 | 6f 66 20 70 61 72 63 65 | number |of parce|
|000033a0| 6c 73 20 73 68 69 70 70 | 65 64 20 66 6f 72 20 61 |ls shipp|ed for a|
|000033b0| 20 70 61 72 74 69 63 75 | 6c 61 72 20 6d 6f 6e 74 | particu|lar mont|
|000033c0| 68 2e 0a 58 0a 58 43 72 | 65 61 74 69 6e 67 20 61 |h..X.XCr|eating a|
|000033d0| 20 6e 65 77 20 66 69 65 | 6c 64 20 63 68 61 6e 67 | new fie|ld chang|
|000033e0| 65 73 20 74 68 65 20 69 | 6e 74 65 72 6e 61 6c 20 |es the i|nternal |
|000033f0| 40 63 6f 64 65 7b 61 77 | 6b 7d 20 63 6f 70 79 20 |@code{aw|k} copy |
|00003400| 6f 66 20 74 68 65 20 63 | 75 72 72 65 6e 74 0a 58 |of the c|urrent.X|
|00003410| 69 6e 70 75 74 20 72 65 | 63 6f 72 64 2d 2d 2d 74 |input re|cord---t|
|00003420| 68 65 20 76 61 6c 75 65 | 20 6f 66 20 40 63 6f 64 |he value| of @cod|
|00003430| 65 7b 24 30 7d 2e 20 20 | 54 68 75 73 2c 20 69 66 |e{$0}. |Thus, if|
|00003440| 20 79 6f 75 20 64 6f 20 | 40 73 61 6d 70 7b 70 72 | you do |@samp{pr|
|00003450| 69 6e 74 20 24 30 7d 0a | 58 61 66 74 65 72 20 61 |int $0}.|Xafter a|
|00003460| 64 64 69 6e 67 20 61 20 | 66 69 65 6c 64 2c 20 74 |dding a |field, t|
|00003470| 68 65 20 72 65 63 6f 72 | 64 20 70 72 69 6e 74 65 |he recor|d printe|
|00003480| 64 20 69 6e 63 6c 75 64 | 65 73 20 74 68 65 20 6e |d includ|es the n|
|00003490| 65 77 20 66 69 65 6c 64 | 2c 20 77 69 74 68 0a 58 |ew field|, with.X|
|000034a0| 74 68 65 20 61 70 70 72 | 6f 70 72 69 61 74 65 20 |the appr|opriate |
|000034b0| 6e 75 6d 62 65 72 20 6f | 66 20 66 69 65 6c 64 20 |number o|f field |
|000034c0| 73 65 70 61 72 61 74 6f | 72 73 20 62 65 74 77 65 |separato|rs betwe|
|000034d0| 65 6e 20 69 74 20 61 6e | 64 20 74 68 65 20 70 72 |en it an|d the pr|
|000034e0| 65 76 69 6f 75 73 6c 79 | 0a 58 65 78 69 73 74 69 |eviously|.Xexisti|
|000034f0| 6e 67 20 66 69 65 6c 64 | 73 2e 0a 58 0a 58 54 68 |ng field|s..X.XTh|
|00003500| 69 73 20 72 65 63 6f 6d | 70 75 74 61 74 69 6f 6e |is recom|putation|
|00003510| 20 61 66 66 65 63 74 73 | 20 61 6e 64 20 69 73 20 | affects| and is |
|00003520| 61 66 66 65 63 74 65 64 | 20 62 79 20 73 65 76 65 |affected| by seve|
|00003530| 72 61 6c 20 66 65 61 74 | 75 72 65 73 20 6e 6f 74 |ral feat|ures not|
|00003540| 20 79 65 74 0a 58 64 69 | 73 63 75 73 73 65 64 2c | yet.Xdi|scussed,|
|00003550| 20 69 6e 20 70 61 72 74 | 69 63 75 6c 61 72 2c 20 | in part|icular, |
|00003560| 74 68 65 20 40 64 66 6e | 7b 6f 75 74 70 75 74 20 |the @dfn|{output |
|00003570| 66 69 65 6c 64 20 73 65 | 70 61 72 61 74 6f 72 7d |field se|parator}|
|00003580| 2c 20 40 63 6f 64 65 7b | 4f 46 53 7d 2c 0a 58 77 |, @code{|OFS},.Xw|
|00003590| 68 69 63 68 20 69 73 20 | 75 73 65 64 20 74 6f 20 |hich is |used to |
|000035a0| 73 65 70 61 72 61 74 65 | 20 74 68 65 20 66 69 65 |separate| the fie|
|000035b0| 6c 64 73 20 28 40 70 78 | 72 65 66 7b 4f 75 74 70 |lds (@px|ref{Outp|
|000035c0| 75 74 20 53 65 70 61 72 | 61 74 6f 72 73 7d 29 2c |ut Separ|ators}),|
|000035d0| 20 61 6e 64 0a 58 40 63 | 6f 64 65 7b 4e 46 7d 20 | and.X@c|ode{NF} |
|000035e0| 28 74 68 65 20 6e 75 6d | 62 65 72 20 6f 66 20 66 |(the num|ber of f|
|000035f0| 69 65 6c 64 73 3b 20 40 | 70 78 72 65 66 7b 46 69 |ields; @|pxref{Fi|
|00003600| 65 6c 64 73 7d 29 2e 20 | 20 46 6f 72 20 65 78 61 |elds}). | For exa|
|00003610| 6d 70 6c 65 2c 20 74 68 | 65 0a 58 76 61 6c 75 65 |mple, th|e.Xvalue|
|00003620| 20 6f 66 20 40 63 6f 64 | 65 7b 4e 46 7d 20 69 73 | of @cod|e{NF} is|
|00003630| 20 73 65 74 20 74 6f 20 | 74 68 65 20 6e 75 6d 62 | set to |the numb|
|00003640| 65 72 20 6f 66 20 74 68 | 65 20 68 69 67 68 65 73 |er of th|e highes|
|00003650| 74 20 66 69 65 6c 64 20 | 79 6f 75 0a 58 63 72 65 |t field |you.Xcre|
|00003660| 61 74 65 2e 40 72 65 66 | 69 6c 6c 0a 58 0a 58 4e |ate.@ref|ill.X.XN|
|00003670| 6f 74 65 2c 20 68 6f 77 | 65 76 65 72 2c 20 74 68 |ote, how|ever, th|
|00003680| 61 74 20 6d 65 72 65 6c | 79 20 40 65 6d 70 68 7b |at merel|y @emph{|
|00003690| 72 65 66 65 72 65 6e 63 | 69 6e 67 7d 20 61 6e 20 |referenc|ing} an |
|000036a0| 6f 75 74 2d 6f 66 2d 72 | 61 6e 67 65 20 66 69 65 |out-of-r|ange fie|
|000036b0| 6c 64 0a 58 64 6f 65 73 | 20 40 65 6d 70 68 7b 6e |ld.Xdoes| @emph{n|
|000036c0| 6f 74 7d 20 63 68 61 6e | 67 65 20 74 68 65 20 76 |ot} chan|ge the v|
|000036d0| 61 6c 75 65 20 6f 66 20 | 65 69 74 68 65 72 20 40 |alue of |either @|
|000036e0| 63 6f 64 65 7b 24 30 7d | 20 6f 72 20 40 63 6f 64 |code{$0}| or @cod|
|000036f0| 65 7b 4e 46 7d 2e 0a 58 | 52 65 66 65 72 65 6e 63 |e{NF}..X|Referenc|
|00003700| 69 6e 67 20 61 6e 20 6f | 75 74 2d 6f 66 2d 72 61 |ing an o|ut-of-ra|
|00003710| 6e 67 65 20 66 69 65 6c | 64 20 6d 65 72 65 6c 79 |nge fiel|d merely|
|00003720| 20 70 72 6f 64 75 63 65 | 73 20 61 20 6e 75 6c 6c | produce|s a null|
|00003730| 20 73 74 72 69 6e 67 2e | 20 20 46 6f 72 0a 58 65 | string.| For.Xe|
|00003740| 78 61 6d 70 6c 65 3a 40 | 72 65 66 69 6c 6c 0a 58 |xample:@|refill.X|
|00003750| 0a 58 40 65 78 61 6d 70 | 6c 65 0a 58 69 66 20 28 |.X@examp|le.Xif (|
|00003760| 24 28 4e 46 2b 31 29 20 | 21 3d 20 22 22 29 0a 58 |$(NF+1) |!= "").X|
|00003770| 20 20 20 20 70 72 69 6e | 74 20 22 63 61 6e 27 74 | prin|t "can't|
|00003780| 20 68 61 70 70 65 6e 22 | 0a 58 65 6c 73 65 0a 58 | happen"|.Xelse.X|
|00003790| 20 20 20 20 70 72 69 6e | 74 20 22 65 76 65 72 79 | prin|t "every|
|000037a0| 74 68 69 6e 67 20 69 73 | 20 6e 6f 72 6d 61 6c 22 |thing is| normal"|
|000037b0| 0a 58 40 65 6e 64 20 65 | 78 61 6d 70 6c 65 0a 58 |.X@end e|xample.X|
|000037c0| 0a 58 40 6e 6f 69 6e 64 | 65 6e 74 0a 58 73 68 6f |.X@noind|ent.Xsho|
|000037d0| 75 6c 64 20 70 72 69 6e | 74 20 40 73 61 6d 70 7b |uld prin|t @samp{|
|000037e0| 65 76 65 72 79 74 68 69 | 6e 67 20 69 73 20 6e 6f |everythi|ng is no|
|000037f0| 72 6d 61 6c 7d 2c 20 62 | 65 63 61 75 73 65 20 40 |rmal}, b|ecause @|
|00003800| 63 6f 64 65 7b 4e 46 2b | 31 7d 20 69 73 20 63 65 |code{NF+|1} is ce|
|00003810| 72 74 61 69 6e 0a 58 74 | 6f 20 62 65 20 6f 75 74 |rtain.Xt|o be out|
|00003820| 20 6f 66 20 72 61 6e 67 | 65 2e 20 20 28 40 78 72 | of rang|e. (@xr|
|00003830| 65 66 7b 49 66 20 53 74 | 61 74 65 6d 65 6e 74 7d |ef{If St|atement}|
|00003840| 2c 20 66 6f 72 20 6d 6f | 72 65 20 69 6e 66 6f 72 |, for mo|re infor|
|00003850| 6d 61 74 69 6f 6e 20 61 | 62 6f 75 74 0a 58 40 63 |mation a|bout.X@c|
|00003860| 6f 64 65 7b 61 77 6b 7d | 27 73 20 40 63 6f 64 65 |ode{awk}|'s @code|
|00003870| 7b 69 66 2d 65 6c 73 65 | 7d 20 73 74 61 74 65 6d |{if-else|} statem|
|00003880| 65 6e 74 73 2e 29 0a 58 | 0a 58 40 6e 6f 64 65 20 |ents.).X|.X@node |
|00003890| 46 69 65 6c 64 20 53 65 | 70 61 72 61 74 6f 72 73 |Field Se|parators|
|000038a0| 2c 20 4d 75 6c 74 69 70 | 6c 65 20 4c 69 6e 65 2c |, Multip|le Line,|
|000038b0| 20 43 68 61 6e 67 69 6e | 67 20 46 69 65 6c 64 73 | Changin|g Fields|
|000038c0| 2c 20 52 65 61 64 69 6e | 67 20 46 69 6c 65 73 0a |, Readin|g Files.|
|000038d0| 58 40 73 65 63 74 69 6f | 6e 20 53 70 65 63 69 66 |X@sectio|n Specif|
|000038e0| 79 69 6e 67 20 48 6f 77 | 20 46 69 65 6c 64 73 20 |ying How| Fields |
|000038f0| 41 72 65 20 53 65 70 61 | 72 61 74 65 64 0a 58 40 |Are Sepa|rated.X@|
|00003900| 76 69 6e 64 65 78 20 46 | 53 0a 58 40 63 69 6e 64 |vindex F|S.X@cind|
|00003910| 65 78 20 66 69 65 6c 64 | 73 2c 20 73 65 70 61 72 |ex field|s, separ|
|00003920| 61 74 69 6e 67 0a 58 40 | 63 69 6e 64 65 78 20 66 |ating.X@|cindex f|
|00003930| 69 65 6c 64 20 73 65 70 | 61 72 61 74 6f 72 2c 20 |ield sep|arator, |
|00003940| 40 63 6f 64 65 7b 46 53 | 7d 0a 58 40 63 69 6e 64 |@code{FS|}.X@cind|
|00003950| 65 78 20 40 73 61 6d 70 | 7b 2d 46 7d 20 6f 70 74 |ex @samp|{-F} opt|
|00003960| 69 6f 6e 0a 58 0a 58 54 | 68 65 20 77 61 79 20 40 |ion.X.XT|he way @|
|00003970| 63 6f 64 65 7b 61 77 6b | 7d 20 73 70 6c 69 74 73 |code{awk|} splits|
|00003980| 20 61 6e 20 69 6e 70 75 | 74 20 72 65 63 6f 72 64 | an inpu|t record|
|00003990| 20 69 6e 74 6f 20 66 69 | 65 6c 64 73 20 69 73 20 | into fi|elds is |
|000039a0| 63 6f 6e 74 72 6f 6c 6c | 65 64 20 62 79 0a 58 74 |controll|ed by.Xt|
|000039b0| 68 65 20 40 64 66 6e 7b | 66 69 65 6c 64 20 73 65 |he @dfn{|field se|
|000039c0| 70 61 72 61 74 6f 72 7d | 2c 20 77 68 69 63 68 20 |parator}|, which |
|000039d0| 69 73 20 61 20 73 69 6e | 67 6c 65 20 63 68 61 72 |is a sin|gle char|
|000039e0| 61 63 74 65 72 20 6f 72 | 20 61 20 72 65 67 75 6c |acter or| a regul|
|000039f0| 61 72 0a 58 65 78 70 72 | 65 73 73 69 6f 6e 2e 20 |ar.Xexpr|ession. |
|00003a00| 20 40 63 6f 64 65 7b 61 | 77 6b 7d 20 73 63 61 6e | @code{a|wk} scan|
|00003a10| 73 20 74 68 65 20 69 6e | 70 75 74 20 72 65 63 6f |s the in|put reco|
|00003a20| 72 64 20 66 6f 72 20 6d | 61 74 63 68 65 73 20 66 |rd for m|atches f|
|00003a30| 6f 72 20 74 68 65 0a 58 | 73 65 70 61 72 61 74 6f |or the.X|separato|
|00003a40| 72 3b 20 74 68 65 20 66 | 69 65 6c 64 73 20 74 68 |r; the f|ields th|
|00003a50| 65 6d 73 65 6c 76 65 73 | 20 61 72 65 20 74 68 65 |emselves| are the|
|00003a60| 20 74 65 78 74 20 62 65 | 74 77 65 65 6e 20 74 68 | text be|tween th|
|00003a70| 65 20 6d 61 74 63 68 65 | 73 2e 20 20 46 6f 72 0a |e matche|s. For.|
|00003a80| 58 65 78 61 6d 70 6c 65 | 2c 20 69 66 20 74 68 65 |Xexample|, if the|
|00003a90| 20 66 69 65 6c 64 20 73 | 65 70 61 72 61 74 6f 72 | field s|eparator|
|00003aa0| 20 69 73 20 40 73 61 6d | 70 7b 6f 6f 7d 2c 20 74 | is @sam|p{oo}, t|
|00003ab0| 68 65 6e 20 74 68 65 20 | 66 6f 6c 6c 6f 77 69 6e |hen the |followin|
|00003ac0| 67 20 6c 69 6e 65 3a 0a | 58 0a 58 40 65 78 61 6d |g line:.|X.X@exam|
|00003ad0| 70 6c 65 0a 58 6d 6f 6f | 20 67 6f 6f 20 67 61 69 |ple.Xmoo| goo gai|
|00003ae0| 20 70 61 6e 0a 58 40 65 | 6e 64 20 65 78 61 6d 70 | pan.X@e|nd examp|
|00003af0| 6c 65 0a 58 0a 58 40 6e | 6f 69 6e 64 65 6e 74 0a |le.X.X@n|oindent.|
|00003b00| 58 77 6f 75 6c 64 20 62 | 65 20 73 70 6c 69 74 20 |Xwould b|e split |
|00003b10| 69 6e 74 6f 20 74 68 72 | 65 65 20 66 69 65 6c 64 |into thr|ee field|
|00003b20| 73 3a 20 40 73 61 6d 70 | 7b 6d 7d 2c 20 40 73 61 |s: @samp|{m}, @sa|
|00003b30| 6d 70 7b 40 20 67 7d 20 | 61 6e 64 20 40 73 61 6d |mp{@ g} |and @sam|
|00003b40| 70 7b 40 20 67 61 69 40 | 20 0a 58 70 61 6e 7d 2e |p{@ gai@| .Xpan}.|
|00003b50| 0a 58 0a 58 54 68 65 20 | 66 69 65 6c 64 20 73 65 |.X.XThe |field se|
|00003b60| 70 61 72 61 74 6f 72 20 | 69 73 20 72 65 70 72 65 |parator |is repre|
|00003b70| 73 65 6e 74 65 64 20 62 | 79 20 74 68 65 20 62 75 |sented b|y the bu|
|00003b80| 69 6c 74 2d 69 6e 20 76 | 61 72 69 61 62 6c 65 20 |ilt-in v|ariable |
|00003b90| 40 63 6f 64 65 7b 46 53 | 7d 2e 0a 58 53 68 65 6c |@code{FS|}..XShel|
|00003ba0| 6c 20 70 72 6f 67 72 61 | 6d 6d 65 72 73 20 74 61 |l progra|mmers ta|
|00003bb0| 6b 65 20 6e 6f 74 65 21 | 20 20 40 63 6f 64 65 7b |ke note!| @code{|
|00003bc0| 61 77 6b 7d 20 64 6f 65 | 73 20 6e 6f 74 20 75 73 |awk} doe|s not us|
|00003bd0| 65 20 74 68 65 20 6e 61 | 6d 65 0a 58 40 63 6f 64 |e the na|me.X@cod|
|00003be0| 65 7b 49 46 53 7d 20 77 | 68 69 63 68 20 69 73 20 |e{IFS} w|hich is |
|00003bf0| 75 73 65 64 20 62 79 20 | 74 68 65 20 73 68 65 6c |used by |the shel|
|00003c00| 6c 2e 40 72 65 66 69 6c | 6c 0a 58 0a 58 59 6f 75 |l.@refil|l.X.XYou|
|00003c10| 20 63 61 6e 20 63 68 61 | 6e 67 65 20 74 68 65 20 | can cha|nge the |
|00003c20| 76 61 6c 75 65 20 6f 66 | 20 40 63 6f 64 65 7b 46 |value of| @code{F|
|00003c30| 53 7d 20 69 6e 20 74 68 | 65 20 40 63 6f 64 65 7b |S} in th|e @code{|
|00003c40| 61 77 6b 7d 20 70 72 6f | 67 72 61 6d 20 77 69 74 |awk} pro|gram wit|
|00003c50| 68 20 74 68 65 0a 58 61 | 73 73 69 67 6e 6d 65 6e |h the.Xa|ssignmen|
|00003c60| 74 20 6f 70 65 72 61 74 | 6f 72 2c 20 40 73 61 6d |t operat|or, @sam|
|00003c70| 70 7b 3d 7d 20 28 40 70 | 78 72 65 66 7b 41 73 73 |p{=} (@p|xref{Ass|
|00003c80| 69 67 6e 6d 65 6e 74 20 | 4f 70 73 7d 29 2e 20 20 |ignment |Ops}). |
|00003c90| 4f 66 74 65 6e 20 74 68 | 65 20 72 69 67 68 74 0a |Often th|e right.|
|00003ca0| 58 74 69 6d 65 20 74 6f | 20 64 6f 20 74 68 69 73 |Xtime to| do this|
|00003cb0| 20 69 73 20 61 74 20 74 | 68 65 20 62 65 67 69 6e | is at t|he begin|
|00003cc0| 6e 69 6e 67 20 6f 66 20 | 65 78 65 63 75 74 69 6f |ning of |executio|
|00003cd0| 6e 2c 20 62 65 66 6f 72 | 65 20 61 6e 79 20 69 6e |n, befor|e any in|
|00003ce0| 70 75 74 20 68 61 73 0a | 58 62 65 65 6e 20 70 72 |put has.|Xbeen pr|
|00003cf0| 6f 63 65 73 73 65 64 2c | 20 73 6f 20 74 68 61 74 |ocessed,| so that|
|00003d00| 20 74 68 65 20 76 65 72 | 79 20 66 69 72 73 74 20 | the ver|y first |
|00003d10| 72 65 63 6f 72 64 20 77 | 69 6c 6c 20 62 65 20 72 |record w|ill be r|
|00003d20| 65 61 64 20 77 69 74 68 | 20 74 68 65 0a 58 70 72 |ead with| the.Xpr|
|00003d30| 6f 70 65 72 20 73 65 70 | 61 72 61 74 6f 72 2e 20 |oper sep|arator. |
|00003d40| 20 54 6f 20 64 6f 20 74 | 68 69 73 2c 20 75 73 65 | To do t|his, use|
|00003d50| 20 74 68 65 20 73 70 65 | 63 69 61 6c 20 40 63 6f | the spe|cial @co|
|00003d60| 64 65 7b 42 45 47 49 4e | 7d 20 70 61 74 74 65 72 |de{BEGIN|} patter|
|00003d70| 6e 0a 58 28 40 70 78 72 | 65 66 7b 42 45 47 49 4e |n.X(@pxr|ef{BEGIN|
|00003d80| 2f 45 4e 44 7d 29 2e 20 | 20 46 6f 72 20 65 78 61 |/END}). | For exa|
|00003d90| 6d 70 6c 65 2c 20 68 65 | 72 65 20 77 65 20 73 65 |mple, he|re we se|
|00003da0| 74 20 74 68 65 20 76 61 | 6c 75 65 20 6f 66 20 40 |t the va|lue of @|
|00003db0| 63 6f 64 65 7b 46 53 7d | 20 74 6f 0a 58 74 68 65 |code{FS}| to.Xthe|
|00003dc0| 20 73 74 72 69 6e 67 20 | 40 63 6f 64 65 7b 22 2c | string |@code{",|
|00003dd0| 22 7d 3a 0a 58 0a 58 40 | 65 78 61 6d 70 6c 65 0a |"}:.X.X@|example.|
|00003de0| 58 61 77 6b 20 27 42 45 | 47 49 4e 20 40 7b 20 46 |Xawk 'BE|GIN @{ F|
|00003df0| 53 20 3d 20 22 2c 22 20 | 40 7d 20 3b 20 40 7b 20 |S = "," |@} ; @{ |
|00003e00| 70 72 69 6e 74 20 24 32 | 20 40 7d 27 0a 58 40 65 |print $2| @}'.X@e|
|00003e10| 6e 64 20 65 78 61 6d 70 | 6c 65 0a 58 0a 58 40 6e |nd examp|le.X.X@n|
|00003e20| 6f 69 6e 64 65 6e 74 0a | 58 47 69 76 65 6e 20 74 |oindent.|XGiven t|
|00003e30| 68 65 20 69 6e 70 75 74 | 20 6c 69 6e 65 2c 0a 58 |he input| line,.X|
|00003e40| 0a 58 40 65 78 61 6d 70 | 6c 65 0a 58 4a 6f 68 6e |.X@examp|le.XJohn|
|00003e50| 20 51 2e 20 53 6d 69 74 | 68 2c 20 32 39 20 4f 61 | Q. Smit|h, 29 Oa|
|00003e60| 6b 20 53 74 2e 2c 20 57 | 61 6c 61 6d 61 7a 6f 6f |k St., W|alamazoo|
|00003e70| 2c 20 4d 49 20 34 32 31 | 33 39 0a 58 40 65 6e 64 |, MI 421|39.X@end|
|00003e80| 20 65 78 61 6d 70 6c 65 | 0a 58 0a 58 40 6e 6f 69 | example|.X.X@noi|
|00003e90| 6e 64 65 6e 74 0a 58 74 | 68 69 73 20 40 63 6f 64 |ndent.Xt|his @cod|
|00003ea0| 65 7b 61 77 6b 7d 20 70 | 72 6f 67 72 61 6d 20 65 |e{awk} p|rogram e|
|00003eb0| 78 74 72 61 63 74 73 20 | 74 68 65 20 73 74 72 69 |xtracts |the stri|
|00003ec0| 6e 67 20 40 73 61 6d 70 | 7b 32 39 20 4f 61 6b 20 |ng @samp|{29 Oak |
|00003ed0| 53 74 2e 7d 2e 0a 58 0a | 58 40 63 69 6e 64 65 78 |St.}..X.|X@cindex|
|00003ee0| 20 66 69 65 6c 64 20 73 | 65 70 61 72 61 74 6f 72 | field s|eparator|
|00003ef0| 2c 20 63 68 6f 69 63 65 | 20 6f 66 0a 58 40 63 69 |, choice| of.X@ci|
|00003f00| 6e 64 65 78 20 72 65 67 | 75 6c 61 72 20 65 78 70 |ndex reg|ular exp|
|00003f10| 72 65 73 73 69 6f 6e 73 | 20 61 73 20 66 69 65 6c |ressions| as fiel|
|00003f20| 64 20 73 65 70 61 72 61 | 74 6f 72 73 0a 58 53 6f |d separa|tors.XSo|
|00003f30| 6d 65 74 69 6d 65 73 20 | 79 6f 75 72 20 69 6e 70 |metimes |your inp|
|00003f40| 75 74 20 64 61 74 61 20 | 77 69 6c 6c 20 63 6f 6e |ut data |will con|
|00003f50| 74 61 69 6e 20 73 65 70 | 61 72 61 74 6f 72 20 63 |tain sep|arator c|
|00003f60| 68 61 72 61 63 74 65 72 | 73 20 74 68 61 74 20 64 |haracter|s that d|
|00003f70| 6f 6e 27 74 0a 58 73 65 | 70 61 72 61 74 65 20 66 |on't.Xse|parate f|
|00003f80| 69 65 6c 64 73 20 74 68 | 65 20 77 61 79 20 79 6f |ields th|e way yo|
|00003f90| 75 20 74 68 6f 75 67 68 | 74 20 74 68 65 79 20 77 |u though|t they w|
|00003fa0| 6f 75 6c 64 2e 20 20 46 | 6f 72 20 69 6e 73 74 61 |ould. F|or insta|
|00003fb0| 6e 63 65 2c 20 74 68 65 | 0a 58 70 65 72 73 6f 6e |nce, the|.Xperson|
|00003fc0| 27 73 20 6e 61 6d 65 20 | 69 6e 20 74 68 65 20 65 |'s name |in the e|
|00003fd0| 78 61 6d 70 6c 65 20 77 | 65 27 76 65 20 62 65 65 |xample w|e've bee|
|00003fe0| 6e 20 75 73 69 6e 67 20 | 6d 69 67 68 74 20 68 61 |n using |might ha|
|00003ff0| 76 65 20 61 20 74 69 74 | 6c 65 20 6f 72 0a 58 73 |ve a tit|le or.Xs|
|00004000| 75 66 66 69 78 20 61 74 | 74 61 63 68 65 64 2c 20 |uffix at|tached, |
|00004010| 73 75 63 68 20 61 73 20 | 40 73 61 6d 70 7b 4a 6f |such as |@samp{Jo|
|00004020| 68 6e 20 51 2e 20 53 6d | 69 74 68 2c 20 4c 58 49 |hn Q. Sm|ith, LXI|
|00004030| 58 7d 2e 20 20 46 72 6f | 6d 20 69 6e 70 75 74 0a |X}. Fro|m input.|
|00004040| 58 63 6f 6e 74 61 69 6e | 69 6e 67 20 73 75 63 68 |Xcontain|ing such|
|00004050| 20 61 20 6e 61 6d 65 3a | 0a 58 0a 58 40 65 78 61 | a name:|.X.X@exa|
|00004060| 6d 70 6c 65 0a 58 4a 6f | 68 6e 20 51 2e 20 53 6d |mple.XJo|hn Q. Sm|
|00004070| 69 74 68 2c 20 4c 58 49 | 58 2c 20 32 39 20 4f 61 |ith, LXI|X, 29 Oa|
|00004080| 6b 20 53 74 2e 2c 20 57 | 61 6c 61 6d 61 7a 6f 6f |k St., W|alamazoo|
|00004090| 2c 20 4d 49 20 34 32 31 | 33 39 0a 58 40 65 6e 64 |, MI 421|39.X@end|
|000040a0| 20 65 78 61 6d 70 6c 65 | 0a 58 0a 58 40 6e 6f 69 | example|.X.X@noi|
|000040b0| 6e 64 65 6e 74 0a 58 74 | 68 65 20 70 72 65 76 69 |ndent.Xt|he previ|
|000040c0| 6f 75 73 20 73 61 6d 70 | 6c 65 20 70 72 6f 67 72 |ous samp|le progr|
|000040d0| 61 6d 20 77 6f 75 6c 64 | 20 65 78 74 72 61 63 74 |am would| extract|
|000040e0| 20 40 73 61 6d 70 7b 4c | 58 49 58 7d 2c 20 69 6e | @samp{L|XIX}, in|
|000040f0| 73 74 65 61 64 20 6f 66 | 0a 58 40 73 61 6d 70 7b |stead of|.X@samp{|
|00004100| 32 39 20 4f 61 6b 20 53 | 74 2e 7d 2e 20 20 49 66 |29 Oak S|t.}. If|
|00004110| 20 79 6f 75 20 77 65 72 | 65 20 65 78 70 65 63 74 | you wer|e expect|
|00004120| 69 6e 67 20 74 68 65 20 | 70 72 6f 67 72 61 6d 20 |ing the |program |
|00004130| 74 6f 20 70 72 69 6e 74 | 20 74 68 65 0a 58 61 64 |to print| the.Xad|
|00004140| 64 72 65 73 73 2c 20 79 | 6f 75 20 77 6f 75 6c 64 |dress, y|ou would|
|00004150| 20 62 65 20 73 75 72 70 | 72 69 73 65 64 2e 20 20 | be surp|rised. |
|00004160| 53 6f 20 63 68 6f 6f 73 | 65 20 79 6f 75 72 20 64 |So choos|e your d|
|00004170| 61 74 61 20 6c 61 79 6f | 75 74 20 61 6e 64 0a 58 |ata layo|ut and.X|
|00004180| 73 65 70 61 72 61 74 6f | 72 20 63 68 61 72 61 63 |separato|r charac|
|00004190| 74 65 72 73 20 63 61 72 | 65 66 75 6c 6c 79 20 74 |ters car|efully t|
|000041a0| 6f 20 70 72 65 76 65 6e | 74 20 73 75 63 68 20 70 |o preven|t such p|
|000041b0| 72 6f 62 6c 65 6d 73 2e | 0a 58 0a 58 41 73 20 79 |roblems.|.X.XAs y|
|000041c0| 6f 75 20 6b 6e 6f 77 2c | 20 62 79 20 64 65 66 61 |ou know,| by defa|
|000041d0| 75 6c 74 2c 20 66 69 65 | 6c 64 73 20 61 72 65 20 |ult, fie|lds are |
|000041e0| 73 65 70 61 72 61 74 65 | 64 20 62 79 20 77 68 69 |separate|d by whi|
|000041f0| 74 65 73 70 61 63 65 20 | 73 65 71 75 65 6e 63 65 |tespace |sequence|
|00004200| 73 0a 58 28 73 70 61 63 | 65 73 20 61 6e 64 20 74 |s.X(spac|es and t|
|00004210| 61 62 73 29 2c 20 6e 6f | 74 20 62 79 20 73 69 6e |abs), no|t by sin|
|00004220| 67 6c 65 20 73 70 61 63 | 65 73 3a 20 74 77 6f 20 |gle spac|es: two |
|00004230| 73 70 61 63 65 73 20 69 | 6e 20 61 20 72 6f 77 20 |spaces i|n a row |
|00004240| 64 6f 20 6e 6f 74 0a 58 | 64 65 6c 69 6d 69 74 20 |do not.X|delimit |
|00004250| 61 6e 20 65 6d 70 74 79 | 20 66 69 65 6c 64 2e 20 |an empty| field. |
|00004260| 20 54 68 65 20 64 65 66 | 61 75 6c 74 20 76 61 6c | The def|ault val|
|00004270| 75 65 20 6f 66 20 74 68 | 65 20 66 69 65 6c 64 20 |ue of th|e field |
|00004280| 73 65 70 61 72 61 74 6f | 72 20 69 73 20 61 0a 58 |separato|r is a.X|
|00004290| 73 74 72 69 6e 67 20 40 | 77 7b 40 63 6f 64 65 7b |string @|w{@code{|
|000042a0| 22 20 22 7d 7d 20 63 6f | 6e 74 61 69 6e 69 6e 67 |" "}} co|ntaining|
|000042b0| 20 61 20 73 69 6e 67 6c | 65 20 73 70 61 63 65 2e | a singl|e space.|
|000042c0| 20 20 49 66 20 74 68 69 | 73 20 76 61 6c 75 65 20 | If thi|s value |
|000042d0| 77 65 72 65 0a 58 69 6e | 74 65 72 70 72 65 74 65 |were.Xin|terprete|
|000042e0| 64 20 69 6e 20 74 68 65 | 20 75 73 75 61 6c 20 77 |d in the| usual w|
|000042f0| 61 79 2c 20 65 61 63 68 | 20 73 70 61 63 65 20 63 |ay, each| space c|
|00004300| 68 61 72 61 63 74 65 72 | 20 77 6f 75 6c 64 20 73 |haracter| would s|
|00004310| 65 70 61 72 61 74 65 0a | 58 66 69 65 6c 64 73 2c |eparate.|Xfields,|
|00004320| 20 73 6f 20 74 77 6f 20 | 73 70 61 63 65 73 20 69 | so two |spaces i|
|00004330| 6e 20 61 20 72 6f 77 20 | 77 6f 75 6c 64 20 6d 61 |n a row |would ma|
|00004340| 6b 65 20 61 6e 20 65 6d | 70 74 79 20 66 69 65 6c |ke an em|pty fiel|
|00004350| 64 20 62 65 74 77 65 65 | 6e 20 74 68 65 6d 2e 0a |d betwee|n them..|
|00004360| 58 54 68 65 20 72 65 61 | 73 6f 6e 20 74 68 69 73 |XThe rea|son this|
|00004370| 20 64 6f 65 73 20 6e 6f | 74 20 68 61 70 70 65 6e | does no|t happen|
|00004380| 20 69 73 20 74 68 61 74 | 20 61 20 73 69 6e 67 6c | is that| a singl|
|00004390| 65 20 73 70 61 63 65 20 | 61 73 20 74 68 65 20 76 |e space |as the v|
|000043a0| 61 6c 75 65 20 6f 66 0a | 58 40 63 6f 64 65 7b 46 |alue of.|X@code{F|
|000043b0| 53 7d 20 69 73 20 61 20 | 73 70 65 63 69 61 6c 20 |S} is a |special |
|000043c0| 63 61 73 65 3a 20 69 74 | 20 69 73 20 74 61 6b 65 |case: it| is take|
|000043d0| 6e 20 74 6f 20 73 70 65 | 63 69 66 79 20 74 68 65 |n to spe|cify the|
|000043e0| 20 64 65 66 61 75 6c 74 | 20 6d 61 6e 6e 65 72 0a | default| manner.|
|000043f0| 58 6f 66 20 64 65 6c 69 | 6d 69 74 69 6e 67 20 66 |Xof deli|miting f|
|00004400| 69 65 6c 64 73 2e 0a 58 | 0a 58 49 66 20 40 63 6f |ields..X|.XIf @co|
|00004410| 64 65 7b 46 53 7d 20 69 | 73 20 61 6e 79 20 6f 74 |de{FS} i|s any ot|
|00004420| 68 65 72 20 73 69 6e 67 | 6c 65 20 63 68 61 72 61 |her sing|le chara|
|00004430| 63 74 65 72 2c 20 73 75 | 63 68 20 61 73 20 40 63 |cter, su|ch as @c|
|00004440| 6f 64 65 7b 22 2c 22 7d | 2c 20 74 68 65 6e 0a 58 |ode{","}|, then.X|
|00004450| 65 61 63 68 20 6f 63 63 | 75 72 72 65 6e 63 65 20 |each occ|urrence |
|00004460| 6f 66 20 74 68 61 74 20 | 63 68 61 72 61 63 74 65 |of that |characte|
|00004470| 72 20 73 65 70 61 72 61 | 74 65 73 20 74 77 6f 20 |r separa|tes two |
|00004480| 66 69 65 6c 64 73 2e 20 | 20 54 77 6f 20 63 6f 6e |fields. | Two con|
|00004490| 73 65 63 75 74 69 76 65 | 0a 58 6f 63 63 75 72 72 |secutive|.Xoccurr|
|000044a0| 65 6e 63 65 73 20 64 65 | 6c 69 6d 69 74 20 61 6e |ences de|limit an|
|000044b0| 20 65 6d 70 74 79 20 66 | 69 65 6c 64 2e 20 20 49 | empty f|ield. I|
|000044c0| 66 20 74 68 65 20 63 68 | 61 72 61 63 74 65 72 20 |f the ch|aracter |
|000044d0| 6f 63 63 75 72 73 20 61 | 74 20 74 68 65 0a 58 62 |occurs a|t the.Xb|
|000044e0| 65 67 69 6e 6e 69 6e 67 | 20 6f 72 20 74 68 65 20 |eginning| or the |
|000044f0| 65 6e 64 20 6f 66 20 74 | 68 65 20 6c 69 6e 65 2c |end of t|he line,|
|00004500| 20 74 68 61 74 20 74 6f | 6f 20 64 65 6c 69 6d 69 | that to|o delimi|
|00004510| 74 73 20 61 6e 20 65 6d | 70 74 79 20 66 69 65 6c |ts an em|pty fiel|
|00004520| 64 2e 20 20 54 68 65 0a | 58 73 70 61 63 65 20 63 |d. The.|Xspace c|
|00004530| 68 61 72 61 63 74 65 72 | 20 69 73 20 74 68 65 20 |haracter| is the |
|00004540| 6f 6e 6c 79 20 73 69 6e | 67 6c 65 20 63 68 61 72 |only sin|gle char|
|00004550| 61 63 74 65 72 20 77 68 | 69 63 68 20 64 6f 65 73 |acter wh|ich does|
|00004560| 20 6e 6f 74 20 66 6f 6c | 6c 6f 77 20 74 68 65 73 | not fol|low thes|
|00004570| 65 0a 58 72 75 6c 65 73 | 2e 0a 58 0a 58 4d 6f 72 |e.Xrules|..X.XMor|
|00004580| 65 20 67 65 6e 65 72 61 | 6c 6c 79 2c 20 74 68 65 |e genera|lly, the|
|00004590| 20 76 61 6c 75 65 20 6f | 66 20 40 63 6f 64 65 7b | value o|f @code{|
|000045a0| 46 53 7d 20 6d 61 79 20 | 62 65 20 61 20 73 74 72 |FS} may |be a str|
|000045b0| 69 6e 67 20 63 6f 6e 74 | 61 69 6e 69 6e 67 20 61 |ing cont|aining a|
|000045c0| 6e 79 0a 58 72 65 67 75 | 6c 61 72 20 65 78 70 72 |ny.Xregu|lar expr|
|000045d0| 65 73 73 69 6f 6e 2e 20 | 20 54 68 65 6e 20 65 61 |ession. | Then ea|
|000045e0| 63 68 20 6d 61 74 63 68 | 20 69 6e 20 74 68 65 20 |ch match| in the |
|000045f0| 72 65 63 6f 72 64 20 66 | 6f 72 20 74 68 65 20 72 |record f|or the r|
|00004600| 65 67 75 6c 61 72 0a 58 | 65 78 70 72 65 73 73 69 |egular.X|expressi|
|00004610| 6f 6e 20 73 65 70 61 72 | 61 74 65 73 20 66 69 65 |on separ|ates fie|
|00004620| 6c 64 73 2e 20 20 46 6f | 72 20 65 78 61 6d 70 6c |lds. Fo|r exampl|
|00004630| 65 2c 20 74 68 65 20 61 | 73 73 69 67 6e 6d 65 6e |e, the a|ssignmen|
|00004640| 74 3a 40 72 65 66 69 6c | 6c 0a 58 0a 58 40 65 78 |t:@refil|l.X.X@ex|
|00004650| 61 6d 70 6c 65 0a 58 46 | 53 20 3d 20 22 2c 20 5c |ample.XF|S = ", \|
|00004660| 74 22 0a 58 40 65 6e 64 | 20 65 78 61 6d 70 6c 65 |t".X@end| example|
|00004670| 0a 58 0a 58 40 6e 6f 69 | 6e 64 65 6e 74 0a 58 6d |.X.X@noi|ndent.Xm|
|00004680| 61 6b 65 73 20 65 76 65 | 72 79 20 61 72 65 61 20 |akes eve|ry area |
|00004690| 6f 66 20 61 6e 20 69 6e | 70 75 74 20 6c 69 6e 65 |of an in|put line|
|000046a0| 20 74 68 61 74 20 63 6f | 6e 73 69 73 74 73 20 6f | that co|nsists o|
|000046b0| 66 20 61 20 63 6f 6d 6d | 61 20 66 6f 6c 6c 6f 77 |f a comm|a follow|
|000046c0| 65 64 20 62 79 20 61 0a | 58 73 70 61 63 65 20 61 |ed by a.|Xspace a|
|000046d0| 6e 64 20 61 20 74 61 62 | 2c 20 69 6e 74 6f 20 61 |nd a tab|, into a|
|000046e0| 20 66 69 65 6c 64 20 73 | 65 70 61 72 61 74 6f 72 | field s|eparator|
|000046f0| 2e 20 20 28 40 73 61 6d | 70 7b 5c 74 7d 20 73 74 |. (@sam|p{\t} st|
|00004700| 61 6e 64 73 20 66 6f 72 | 20 61 0a 58 74 61 62 2e |ands for| a.Xtab.|
|00004710| 29 40 72 65 66 69 6c 6c | 0a 58 0a 58 46 6f 72 20 |)@refill|.X.XFor |
|00004720| 61 20 6c 65 73 73 20 74 | 72 69 76 69 61 6c 20 65 |a less t|rivial e|
|00004730| 78 61 6d 70 6c 65 20 6f | 66 20 61 20 72 65 67 75 |xample o|f a regu|
|00004740| 6c 61 72 20 65 78 70 72 | 65 73 73 69 6f 6e 2c 20 |lar expr|ession, |
|00004750| 73 75 70 70 6f 73 65 20 | 79 6f 75 20 77 61 6e 74 |suppose |you want|
|00004760| 0a 58 73 69 6e 67 6c 65 | 20 73 70 61 63 65 73 20 |.Xsingle| spaces |
|00004770| 74 6f 20 73 65 70 61 72 | 61 74 65 20 66 69 65 6c |to separ|ate fiel|
|00004780| 64 73 20 74 68 65 20 77 | 61 79 20 73 69 6e 67 6c |ds the w|ay singl|
|00004790| 65 20 63 6f 6d 6d 61 73 | 20 77 65 72 65 20 75 73 |e commas| were us|
|000047a0| 65 64 20 61 62 6f 76 65 | 2e 0a 58 59 6f 75 20 63 |ed above|..XYou c|
|000047b0| 61 6e 20 73 65 74 20 40 | 63 6f 64 65 7b 46 53 7d |an set @|code{FS}|
|000047c0| 20 74 6f 20 40 77 7b 40 | 63 6f 64 65 7b 22 5b 40 | to @w{@|code{"[@|
|000047d0| 20 5d 22 7d 7d 2e 20 20 | 54 68 69 73 20 72 65 67 | ]"}}. |This reg|
|000047e0| 75 6c 61 72 20 65 78 70 | 72 65 73 73 69 6f 6e 0a |ular exp|ression.|
|000047f0| 58 6d 61 74 63 68 65 73 | 20 61 20 73 69 6e 67 6c |Xmatches| a singl|
|00004800| 65 20 73 70 61 63 65 20 | 61 6e 64 20 6e 6f 74 68 |e space |and noth|
|00004810| 69 6e 67 20 65 6c 73 65 | 2e 0a 58 0a 58 40 63 69 |ing else|..X.X@ci|
|00004820| 6e 64 65 78 20 66 69 65 | 6c 64 20 73 65 70 61 72 |ndex fie|ld separ|
|00004830| 61 74 6f 72 2c 20 73 65 | 74 74 69 6e 67 20 6f 6e |ator, se|tting on|
|00004840| 20 63 6f 6d 6d 61 6e 64 | 20 6c 69 6e 65 0a 58 40 | command| line.X@|
|00004850| 63 69 6e 64 65 78 20 63 | 6f 6d 6d 61 6e 64 20 6c |cindex c|ommand l|
|00004860| 69 6e 65 2c 20 73 65 74 | 74 69 6e 67 20 40 63 6f |ine, set|ting @co|
|00004870| 64 65 7b 46 53 7d 20 6f | 6e 0a 58 40 63 6f 64 65 |de{FS} o|n.X@code|
|00004880| 7b 46 53 7d 20 63 61 6e | 20 62 65 20 73 65 74 20 |{FS} can| be set |
|00004890| 6f 6e 20 74 68 65 20 63 | 6f 6d 6d 61 6e 64 20 6c |on the c|ommand l|
|000048a0| 69 6e 65 2e 20 20 59 6f | 75 20 75 73 65 20 74 68 |ine. Yo|u use th|
|000048b0| 65 20 40 73 61 6d 70 7b | 2d 46 7d 20 61 72 67 75 |e @samp{|-F} argu|
|000048c0| 6d 65 6e 74 20 74 6f 0a | 58 64 6f 20 73 6f 2e 20 |ment to.|Xdo so. |
|000048d0| 20 46 6f 72 20 65 78 61 | 6d 70 6c 65 3a 0a 58 0a | For exa|mple:.X.|
|000048e0| 58 40 65 78 61 6d 70 6c | 65 0a 58 61 77 6b 20 2d |X@exampl|e.Xawk -|
|000048f0| 46 2c 20 27 40 76 61 72 | 7b 70 72 6f 67 72 61 6d |F, '@var|{program|
|00004900| 7d 27 20 40 76 61 72 7b | 69 6e 70 75 74 2d 66 69 |}' @var{|input-fi|
|00004910| 6c 65 73 7d 0a 58 40 65 | 6e 64 20 65 78 61 6d 70 |les}.X@e|nd examp|
|00004920| 6c 65 0a 58 0a 58 40 6e | 6f 69 6e 64 65 6e 74 0a |le.X.X@n|oindent.|
|00004930| 58 73 65 74 73 20 40 63 | 6f 64 65 7b 46 53 7d 20 |Xsets @c|ode{FS} |
|00004940| 74 6f 20 62 65 20 74 68 | 65 20 40 73 61 6d 70 7b |to be th|e @samp{|
|00004950| 2c 7d 20 63 68 61 72 61 | 63 74 65 72 2e 20 20 4e |,} chara|cter. N|
|00004960| 6f 74 69 63 65 20 74 68 | 61 74 20 74 68 65 20 61 |otice th|at the a|
|00004970| 72 67 75 6d 65 6e 74 20 | 75 73 65 73 0a 58 61 20 |rgument |uses.Xa |
|00004980| 63 61 70 69 74 61 6c 20 | 40 73 61 6d 70 7b 46 7d |capital |@samp{F}|
|00004990| 2e 20 20 43 6f 6e 74 72 | 61 73 74 20 74 68 69 73 |. Contr|ast this|
|000049a0| 20 77 69 74 68 20 40 73 | 61 6d 70 7b 2d 66 7d 2c | with @s|amp{-f},|
|000049b0| 20 77 68 69 63 68 20 73 | 70 65 63 69 66 69 65 73 | which s|pecifies|
|000049c0| 20 61 20 66 69 6c 65 0a | 58 63 6f 6e 74 61 69 6e | a file.|Xcontain|
|000049d0| 69 6e 67 20 61 6e 20 40 | 63 6f 64 65 7b 61 77 6b |ing an @|code{awk|
|000049e0| 7d 20 70 72 6f 67 72 61 | 6d 2e 20 20 43 61 73 65 |} progra|m. Case|
|000049f0| 20 69 73 20 73 69 67 6e | 69 66 69 63 61 6e 74 20 | is sign|ificant |
|00004a00| 69 6e 20 63 6f 6d 6d 61 | 6e 64 20 6f 70 74 69 6f |in comma|nd optio|
|00004a10| 6e 73 3a 0a 58 74 68 65 | 20 40 73 61 6d 70 7b 2d |ns:.Xthe| @samp{-|
|00004a20| 46 7d 20 61 6e 64 20 40 | 73 61 6d 70 7b 2d 66 7d |F} and @|samp{-f}|
|00004a30| 20 6f 70 74 69 6f 6e 73 | 20 68 61 76 65 20 6e 6f | options| have no|
|00004a40| 74 68 69 6e 67 20 74 6f | 20 64 6f 20 77 69 74 68 |thing to| do with|
|00004a50| 20 65 61 63 68 20 6f 74 | 68 65 72 2e 0a 58 59 6f | each ot|her..XYo|
|00004a60| 75 20 63 61 6e 20 75 73 | 65 20 62 6f 74 68 20 6f |u can us|e both o|
|00004a70| 70 74 69 6f 6e 73 20 61 | 74 20 74 68 65 20 73 61 |ptions a|t the sa|
|00004a80| 6d 65 20 74 69 6d 65 20 | 74 6f 20 73 65 74 20 74 |me time |to set t|
|00004a90| 68 65 20 40 63 6f 64 65 | 7b 46 53 7d 20 61 72 67 |he @code|{FS} arg|
|00004aa0| 75 6d 65 6e 74 0a 58 40 | 65 6d 70 68 7b 61 6e 64 |ument.X@|emph{and|
|00004ab0| 7d 20 67 65 74 20 61 6e | 20 40 63 6f 64 65 7b 61 |} get an| @code{a|
|00004ac0| 77 6b 7d 20 70 72 6f 67 | 72 61 6d 20 66 72 6f 6d |wk} prog|ram from|
|00004ad0| 20 61 20 66 69 6c 65 2e | 0a 58 0a 58 41 73 20 61 | a file.|.X.XAs a|
|00004ae0| 20 73 70 65 63 69 61 6c | 20 63 61 73 65 2c 20 69 | special| case, i|
|00004af0| 6e 20 63 6f 6d 70 61 74 | 69 62 69 6c 69 74 79 20 |n compat|ibility |
|00004b00| 6d 6f 64 65 20 28 40 70 | 78 72 65 66 7b 43 6f 6d |mode (@p|xref{Com|
|00004b10| 6d 61 6e 64 20 4c 69 6e | 65 7d 29 2c 20 69 66 20 |mand Lin|e}), if |
|00004b20| 74 68 65 0a 58 61 72 67 | 75 6d 65 6e 74 20 74 6f |the.Xarg|ument to|
|00004b30| 20 40 73 61 6d 70 7b 2d | 46 7d 20 69 73 20 40 73 | @samp{-|F} is @s|
|00004b40| 61 6d 70 7b 74 7d 2c 20 | 74 68 65 6e 20 40 63 6f |amp{t}, |then @co|
|00004b50| 64 65 7b 46 53 7d 20 69 | 73 20 73 65 74 20 74 6f |de{FS} i|s set to|
|00004b60| 20 74 68 65 20 74 61 62 | 0a 58 63 68 61 72 61 63 | the tab|.Xcharac|
|00004b70| 74 65 72 2e 20 20 28 54 | 68 69 73 20 69 73 20 62 |ter. (T|his is b|
|00004b80| 65 63 61 75 73 65 20 69 | 66 20 79 6f 75 20 74 79 |ecause i|f you ty|
|00004b90| 70 65 20 40 73 61 6d 70 | 7b 2d 46 5c 74 7d 2c 20 |pe @samp|{-F\t}, |
|00004ba0| 77 69 74 68 6f 75 74 20 | 74 68 65 20 71 75 6f 74 |without |the quot|
|00004bb0| 65 73 2c 0a 58 61 74 20 | 74 68 65 20 73 68 65 6c |es,.Xat |the shel|
|00004bc0| 6c 2c 20 74 68 65 20 40 | 73 61 6d 70 7b 5c 7d 20 |l, the @|samp{\} |
|00004bd0| 67 65 74 73 20 64 65 6c | 65 74 65 64 2c 20 73 6f |gets del|eted, so|
|00004be0| 20 40 63 6f 64 65 7b 61 | 77 6b 7d 20 66 69 67 75 | @code{a|wk} figu|
|00004bf0| 72 65 73 20 74 68 61 74 | 20 79 6f 75 0a 58 72 65 |res that| you.Xre|
|00004c00| 61 6c 6c 79 20 77 61 6e | 74 20 79 6f 75 72 20 66 |ally wan|t your f|
|00004c10| 69 65 6c 64 73 20 74 6f | 20 62 65 20 73 65 70 61 |ields to| be sepa|
|00004c20| 72 61 74 65 64 20 77 69 | 74 68 20 74 61 62 73 2c |rated wi|th tabs,|
|00004c30| 20 61 6e 64 20 6e 6f 74 | 20 40 73 61 6d 70 7b 74 | and not| @samp{t|
|00004c40| 7d 73 2e 0a 58 55 73 65 | 20 40 73 61 6d 70 7b 46 |}s..XUse| @samp{F|
|00004c50| 53 3d 22 74 22 7d 20 6f | 6e 20 74 68 65 20 63 6f |S="t"} o|n the co|
|00004c60| 6d 6d 61 6e 64 20 6c 69 | 6e 65 20 69 66 20 79 6f |mmand li|ne if yo|
|00004c70| 75 20 72 65 61 6c 6c 79 | 20 64 6f 20 77 61 6e 74 |u really| do want|
|00004c80| 20 74 6f 20 73 65 70 61 | 72 61 74 65 0a 58 79 6f | to sepa|rate.Xyo|
|00004c90| 75 72 20 66 69 65 6c 64 | 73 20 77 69 74 68 20 40 |ur field|s with @|
|00004ca0| 73 61 6d 70 7b 74 7d 73 | 2e 29 0a 58 0a 58 46 6f |samp{t}s|.).X.XFo|
|00004cb0| 72 20 65 78 61 6d 70 6c | 65 2c 20 6c 65 74 27 73 |r exampl|e, let's|
|00004cc0| 20 75 73 65 20 61 6e 20 | 40 63 6f 64 65 7b 61 77 | use an |@code{aw|
|00004cd0| 6b 7d 20 70 72 6f 67 72 | 61 6d 20 66 69 6c 65 20 |k} progr|am file |
|00004ce0| 63 61 6c 6c 65 64 20 40 | 66 69 6c 65 7b 62 61 75 |called @|file{bau|
|00004cf0| 64 2e 61 77 6b 7d 0a 58 | 74 68 61 74 20 63 6f 6e |d.awk}.X|that con|
|00004d00| 74 61 69 6e 73 20 74 68 | 65 20 70 61 74 74 65 72 |tains th|e patter|
|00004d10| 6e 20 40 63 6f 64 65 7b | 2f 33 30 30 2f 7d 2c 20 |n @code{|/300/}, |
|00004d20| 61 6e 64 20 74 68 65 20 | 61 63 74 69 6f 6e 20 40 |and the |action @|
|00004d30| 73 61 6d 70 7b 70 72 69 | 6e 74 20 24 31 7d 2e 0a |samp{pri|nt $1}..|
|00004d40| 58 48 65 72 65 20 69 73 | 20 74 68 65 20 70 72 6f |XHere is| the pro|
|00004d50| 67 72 61 6d 3a 0a 58 0a | 58 40 65 78 61 6d 70 6c |gram:.X.|X@exampl|
|00004d60| 65 0a 58 2f 33 30 30 2f | 20 20 20 40 7b 20 70 72 |e.X/300/| @{ pr|
|00004d70| 69 6e 74 20 24 31 20 40 | 7d 0a 58 40 65 6e 64 20 |int $1 @|}.X@end |
|00004d80| 65 78 61 6d 70 6c 65 0a | 58 0a 58 4c 65 74 27 73 |example.|X.XLet's|
|00004d90| 20 61 6c 73 6f 20 73 65 | 74 20 40 63 6f 64 65 7b | also se|t @code{|
|00004da0| 46 53 7d 20 74 6f 20 62 | 65 20 74 68 65 20 40 73 |FS} to b|e the @s|
|00004db0| 61 6d 70 7b 2d 7d 20 63 | 68 61 72 61 63 74 65 72 |amp{-} c|haracter|
|00004dc0| 2c 20 61 6e 64 20 72 75 | 6e 20 74 68 65 0a 58 70 |, and ru|n the.Xp|
|00004dd0| 72 6f 67 72 61 6d 20 6f | 6e 20 74 68 65 20 66 69 |rogram o|n the fi|
|00004de0| 6c 65 20 40 66 69 6c 65 | 7b 42 42 53 2d 6c 69 73 |le @file|{BBS-lis|
|00004df0| 74 7d 2e 20 20 54 68 65 | 20 66 6f 6c 6c 6f 77 69 |t}. The| followi|
|00004e00| 6e 67 20 63 6f 6d 6d 61 | 6e 64 20 70 72 69 6e 74 |ng comma|nd print|
|00004e10| 73 20 61 0a 58 6c 69 73 | 74 20 6f 66 20 74 68 65 |s a.Xlis|t of the|
|00004e20| 20 6e 61 6d 65 73 20 6f | 66 20 74 68 65 20 62 75 | names o|f the bu|
|00004e30| 6c 6c 65 74 69 6e 20 62 | 6f 61 72 64 73 20 74 68 |lletin b|oards th|
|00004e40| 61 74 20 6f 70 65 72 61 | 74 65 20 61 74 20 33 30 |at opera|te at 30|
|00004e50| 30 20 62 61 75 64 20 61 | 6e 64 0a 58 74 68 65 20 |0 baud a|nd.Xthe |
|00004e60| 66 69 72 73 74 20 74 68 | 72 65 65 20 64 69 67 69 |first th|ree digi|
|00004e70| 74 73 20 6f 66 20 74 68 | 65 69 72 20 70 68 6f 6e |ts of th|eir phon|
|00004e80| 65 20 6e 75 6d 62 65 72 | 73 3a 40 72 65 66 69 6c |e number|s:@refil|
|00004e90| 6c 0a 58 0a 58 40 65 78 | 61 6d 70 6c 65 0a 58 61 |l.X.X@ex|ample.Xa|
|00004ea0| 77 6b 20 2d 46 2d 20 2d | 66 20 62 61 75 64 2e 61 |wk -F- -|f baud.a|
|00004eb0| 77 6b 20 42 42 53 2d 6c | 69 73 74 0a 58 40 65 6e |wk BBS-l|ist.X@en|
|00004ec0| 64 20 65 78 61 6d 70 6c | 65 0a 58 0a 58 40 6e 6f |d exampl|e.X.X@no|
|00004ed0| 69 6e 64 65 6e 74 0a 58 | 49 74 20 70 72 6f 64 75 |indent.X|It produ|
|00004ee0| 63 65 73 20 74 68 69 73 | 20 6f 75 74 70 75 74 3a |ces this| output:|
|00004ef0| 0a 58 0a 58 40 65 78 61 | 6d 70 6c 65 0a 58 61 61 |.X.X@exa|mple.Xaa|
|00004f00| 72 64 76 61 72 6b 20 20 | 20 20 20 35 35 35 0a 58 |rdvark | 555.X|
|00004f10| 61 6c 70 6f 0a 58 62 61 | 72 66 6c 79 20 20 20 20 |alpo.Xba|rfly |
|00004f20| 20 20 20 35 35 35 0a 58 | 62 69 74 65 73 20 20 20 | 555.X|bites |
|00004f30| 20 20 20 20 20 35 35 35 | 0a 58 63 61 6d 65 6c 6f | 555|.Xcamelo|
|00004f40| 74 20 20 20 20 20 20 35 | 35 35 0a 58 63 6f 72 65 |t 5|55.Xcore|
|00004f50| 20 20 20 20 20 20 20 20 | 20 35 35 35 0a 58 66 6f | | 555.Xfo|
|00004f60| 6f 65 79 20 20 20 20 20 | 20 20 20 35 35 35 0a 58 |oey | 555.X|
|00004f70| 66 6f 6f 74 20 20 20 20 | 20 20 20 20 20 35 35 35 |foot | 555|
|00004f80| 0a 58 6d 61 63 66 6f 6f | 20 20 20 20 20 20 20 35 |.Xmacfoo| 5|
|00004f90| 35 35 0a 58 73 64 61 63 | 65 20 20 20 20 20 20 20 |55.Xsdac|e |
|00004fa0| 20 35 35 35 0a 58 73 61 | 62 61 66 6f 6f 20 20 20 | 555.Xsa|bafoo |
|00004fb0| 20 20 20 35 35 35 0a 58 | 40 65 6e 64 20 65 78 61 | 555.X|@end exa|
|00004fc0| 6d 70 6c 65 0a 58 0a 58 | 40 6e 6f 69 6e 64 65 6e |mple.X.X|@noinden|
|00004fd0| 74 0a 58 4e 6f 74 65 20 | 74 68 65 20 73 65 63 6f |t.XNote |the seco|
|00004fe0| 6e 64 20 6c 69 6e 65 20 | 6f 66 20 6f 75 74 70 75 |nd line |of outpu|
|00004ff0| 74 2e 20 20 49 66 20 79 | 6f 75 20 63 68 65 63 6b |t. If y|ou check|
|00005000| 20 74 68 65 20 6f 72 69 | 67 69 6e 61 6c 20 66 69 | the ori|ginal fi|
|00005010| 6c 65 2c 20 79 6f 75 20 | 77 69 6c 6c 0a 58 73 65 |le, you |will.Xse|
|00005020| 65 20 74 68 61 74 20 74 | 68 65 20 73 65 63 6f 6e |e that t|he secon|
|00005030| 64 20 6c 69 6e 65 20 6c | 6f 6f 6b 65 64 20 6c 69 |d line l|ooked li|
|00005040| 6b 65 20 74 68 69 73 3a | 0a 58 0a 58 40 65 78 61 |ke this:|.X.X@exa|
|00005050| 6d 70 6c 65 0a 58 61 6c | 70 6f 2d 6e 65 74 20 20 |mple.Xal|po-net |
|00005060| 20 20 20 35 35 35 2d 33 | 34 31 32 20 20 20 20 20 | 555-3|412 |
|00005070| 32 34 30 30 2f 31 32 30 | 30 2f 33 30 30 20 20 20 |2400/120|0/300 |
|00005080| 20 20 41 0a 58 40 65 6e | 64 20 65 78 61 6d 70 6c | A.X@en|d exampl|
|00005090| 65 0a 58 0a 58 54 68 65 | 20 40 73 61 6d 70 7b 2d |e.X.XThe| @samp{-|
|000050a0| 7d 20 61 73 20 70 61 72 | 74 20 6f 66 20 74 68 65 |} as par|t of the|
|000050b0| 20 73 79 73 74 65 6d 27 | 73 20 6e 61 6d 65 20 77 | system'|s name w|
|000050c0| 61 73 20 75 73 65 64 20 | 61 73 20 74 68 65 20 66 |as used |as the f|
|000050d0| 69 65 6c 64 0a 58 73 65 | 70 61 72 61 74 6f 72 2c |ield.Xse|parator,|
|000050e0| 20 69 6e 73 74 65 61 64 | 20 6f 66 20 74 68 65 20 | instead| of the |
|000050f0| 40 73 61 6d 70 7b 2d 7d | 20 69 6e 20 74 68 65 20 |@samp{-}| in the |
|00005100| 70 68 6f 6e 65 20 6e 75 | 6d 62 65 72 20 74 68 61 |phone nu|mber tha|
|00005110| 74 20 77 61 73 0a 58 6f | 72 69 67 69 6e 61 6c 6c |t was.Xo|riginall|
|00005120| 79 20 69 6e 74 65 6e 64 | 65 64 2e 20 20 54 68 69 |y intend|ed. Thi|
|00005130| 73 20 64 65 6d 6f 6e 73 | 74 72 61 74 65 73 20 77 |s demons|trates w|
|00005140| 68 79 20 79 6f 75 20 68 | 61 76 65 20 74 6f 20 62 |hy you h|ave to b|
|00005150| 65 20 63 61 72 65 66 75 | 6c 20 69 6e 0a 58 63 68 |e carefu|l in.Xch|
|00005160| 6f 6f 73 69 6e 67 20 79 | 6f 75 72 20 66 69 65 6c |oosing y|our fiel|
|00005170| 64 20 61 6e 64 20 72 65 | 63 6f 72 64 20 73 65 70 |d and re|cord sep|
|00005180| 61 72 61 74 6f 72 73 2e | 0a 58 0a 58 54 68 65 20 |arators.|.X.XThe |
|00005190| 66 6f 6c 6c 6f 77 69 6e | 67 20 70 72 6f 67 72 61 |followin|g progra|
|000051a0| 6d 20 73 65 61 72 63 68 | 65 73 20 74 68 65 20 73 |m search|es the s|
|000051b0| 79 73 74 65 6d 20 70 61 | 73 73 77 6f 72 64 20 66 |ystem pa|ssword f|
|000051c0| 69 6c 65 2c 20 61 6e 64 | 20 70 72 69 6e 74 73 0a |ile, and| prints.|
|000051d0| 58 74 68 65 20 65 6e 74 | 72 69 65 73 20 66 6f 72 |Xthe ent|ries for|
|000051e0| 20 75 73 65 72 73 20 77 | 68 6f 20 68 61 76 65 20 | users w|ho have |
|000051f0| 6e 6f 20 70 61 73 73 77 | 6f 72 64 3a 0a 58 0a 58 |no passw|ord:.X.X|
|00005200| 40 65 78 61 6d 70 6c 65 | 0a 58 61 77 6b 20 2d 46 |@example|.Xawk -F|
|00005210| 3a 20 27 24 32 20 3d 3d | 20 22 22 27 20 2f 65 74 |: '$2 ==| ""' /et|
|00005220| 63 2f 70 61 73 73 77 64 | 0a 58 40 65 6e 64 20 65 |c/passwd|.X@end e|
|00005230| 78 61 6d 70 6c 65 0a 58 | 0a 58 40 6e 6f 69 6e 64 |xample.X|.X@noind|
|00005240| 65 6e 74 0a 58 48 65 72 | 65 20 77 65 20 75 73 65 |ent.XHer|e we use|
|00005250| 20 74 68 65 20 40 73 61 | 6d 70 7b 2d 46 7d 20 6f | the @sa|mp{-F} o|
|00005260| 70 74 69 6f 6e 20 6f 6e | 20 74 68 65 20 63 6f 6d |ption on| the com|
|00005270| 6d 61 6e 64 20 6c 69 6e | 65 20 74 6f 20 73 65 74 |mand lin|e to set|
|00005280| 20 74 68 65 20 66 69 65 | 6c 64 0a 58 73 65 70 61 | the fie|ld.Xsepa|
|00005290| 72 61 74 6f 72 2e 20 20 | 4e 6f 74 65 20 74 68 61 |rator. |Note tha|
|000052a0| 74 20 66 69 65 6c 64 73 | 20 69 6e 20 40 66 69 6c |t fields| in @fil|
|000052b0| 65 7b 2f 65 74 63 2f 70 | 61 73 73 77 64 7d 20 61 |e{/etc/p|asswd} a|
|000052c0| 72 65 20 73 65 70 61 72 | 61 74 65 64 20 62 79 0a |re separ|ated by.|
|000052d0| 58 63 6f 6c 6f 6e 73 2e | 20 20 54 68 65 20 73 65 |Xcolons.| The se|
|000052e0| 63 6f 6e 64 20 66 69 65 | 6c 64 20 72 65 70 72 65 |cond fie|ld repre|
|000052f0| 73 65 6e 74 73 20 61 20 | 75 73 65 72 27 73 20 65 |sents a |user's e|
|00005300| 6e 63 72 79 70 74 65 64 | 20 70 61 73 73 77 6f 72 |ncrypted| passwor|
|00005310| 64 2c 20 62 75 74 20 69 | 66 0a 58 74 68 65 20 66 |d, but i|f.Xthe f|
|00005320| 69 65 6c 64 20 69 73 20 | 65 6d 70 74 79 2c 20 74 |ield is |empty, t|
|00005330| 68 61 74 20 75 73 65 72 | 20 68 61 73 20 6e 6f 20 |hat user| has no |
|00005340| 70 61 73 73 77 6f 72 64 | 2e 0a 58 0a 58 40 6e 6f |password|..X.X@no|
|00005350| 64 65 20 4d 75 6c 74 69 | 70 6c 65 20 4c 69 6e 65 |de Multi|ple Line|
|00005360| 2c 20 47 65 74 6c 69 6e | 65 2c 20 46 69 65 6c 64 |, Getlin|e, Field|
|00005370| 20 53 65 70 61 72 61 74 | 6f 72 73 2c 20 52 65 61 | Separat|ors, Rea|
|00005380| 64 69 6e 67 20 46 69 6c | 65 73 0a 58 40 73 65 63 |ding Fil|es.X@sec|
|00005390| 74 69 6f 6e 20 4d 75 6c | 74 69 70 6c 65 2d 4c 69 |tion Mul|tiple-Li|
|000053a0| 6e 65 20 52 65 63 6f 72 | 64 73 0a 58 0a 58 40 63 |ne Recor|ds.X.X@c|
|000053b0| 69 6e 64 65 78 20 6d 75 | 6c 74 69 70 6c 65 20 6c |index mu|ltiple l|
|000053c0| 69 6e 65 20 72 65 63 6f | 72 64 73 0a 58 40 63 69 |ine reco|rds.X@ci|
|000053d0| 6e 64 65 78 20 69 6e 70 | 75 74 2c 20 6d 75 6c 74 |ndex inp|ut, mult|
|000053e0| 69 70 6c 65 20 6c 69 6e | 65 20 72 65 63 6f 72 64 |iple lin|e record|
|000053f0| 73 0a 58 40 63 69 6e 64 | 65 78 20 72 65 61 64 69 |s.X@cind|ex readi|
|00005400| 6e 67 20 66 69 6c 65 73 | 2c 20 6d 75 6c 74 69 70 |ng files|, multip|
|00005410| 6c 65 20 6c 69 6e 65 20 | 72 65 63 6f 72 64 73 0a |le line |records.|
|00005420| 58 40 63 69 6e 64 65 78 | 20 72 65 63 6f 72 64 73 |X@cindex| records|
|00005430| 2c 20 6d 75 6c 74 69 70 | 6c 65 20 6c 69 6e 65 0a |, multip|le line.|
|00005440| 58 49 6e 20 73 6f 6d 65 | 20 64 61 74 61 20 62 61 |XIn some| data ba|
|00005450| 73 65 73 2c 20 61 20 73 | 69 6e 67 6c 65 20 6c 69 |ses, a s|ingle li|
|00005460| 6e 65 20 63 61 6e 6e 6f | 74 20 63 6f 6e 76 65 6e |ne canno|t conven|
|00005470| 69 65 6e 74 6c 79 20 68 | 6f 6c 64 20 61 6c 6c 20 |iently h|old all |
|00005480| 74 68 65 0a 58 69 6e 66 | 6f 72 6d 61 74 69 6f 6e |the.Xinf|ormation|
|00005490| 20 69 6e 20 6f 6e 65 20 | 65 6e 74 72 79 2e 20 20 | in one |entry. |
|000054a0| 49 6e 20 73 75 63 68 20 | 63 61 73 65 73 2c 20 79 |In such |cases, y|
|000054b0| 6f 75 20 63 61 6e 20 75 | 73 65 20 6d 75 6c 74 69 |ou can u|se multi|
|000054c0| 2d 6c 69 6e 65 0a 58 72 | 65 63 6f 72 64 73 2e 0a |-line.Xr|ecords..|
|000054d0| 58 0a 58 54 68 65 20 66 | 69 72 73 74 20 73 74 65 |X.XThe f|irst ste|
|000054e0| 70 20 69 6e 20 64 6f 69 | 6e 67 20 74 68 69 73 20 |p in doi|ng this |
|000054f0| 69 73 20 74 6f 20 63 68 | 6f 6f 73 65 20 79 6f 75 |is to ch|oose you|
|00005500| 72 20 64 61 74 61 20 66 | 6f 72 6d 61 74 3a 20 77 |r data f|ormat: w|
|00005510| 68 65 6e 20 72 65 63 6f | 72 64 73 0a 58 61 72 65 |hen reco|rds.Xare|
|00005520| 20 6e 6f 74 20 64 65 66 | 69 6e 65 64 20 61 73 20 | not def|ined as |
|00005530| 73 69 6e 67 6c 65 20 6c | 69 6e 65 73 2c 20 68 6f |single l|ines, ho|
|00005540| 77 20 64 6f 20 79 6f 75 | 20 77 61 6e 74 20 74 6f |w do you| want to|
|00005550| 20 64 65 66 69 6e 65 20 | 74 68 65 6d 3f 0a 58 57 | define |them?.XW|
|00005560| 68 61 74 20 73 68 6f 75 | 6c 64 20 73 65 70 61 72 |hat shou|ld separ|
|00005570| 61 74 65 20 72 65 63 6f | 72 64 73 3f 0a 58 0a 58 |ate reco|rds?.X.X|
|00005580| 4f 6e 65 20 74 65 63 68 | 6e 69 71 75 65 20 69 73 |One tech|nique is|
|00005590| 20 74 6f 20 75 73 65 20 | 61 6e 20 75 6e 75 73 75 | to use |an unusu|
|000055a0| 61 6c 20 63 68 61 72 61 | 63 74 65 72 20 6f 72 20 |al chara|cter or |
|000055b0| 73 74 72 69 6e 67 20 74 | 6f 20 73 65 70 61 72 61 |string t|o separa|
|000055c0| 74 65 0a 58 72 65 63 6f | 72 64 73 2e 20 20 46 6f |te.Xreco|rds. Fo|
|000055d0| 72 20 65 78 61 6d 70 6c | 65 2c 20 79 6f 75 20 63 |r exampl|e, you c|
|000055e0| 6f 75 6c 64 20 75 73 65 | 20 74 68 65 20 66 6f 72 |ould use| the for|
|000055f0| 6d 66 65 65 64 20 63 68 | 61 72 61 63 74 65 72 20 |mfeed ch|aracter |
|00005600| 28 77 72 69 74 74 65 6e | 0a 58 40 73 61 6d 70 7b |(written|.X@samp{|
|00005610| 5c 66 7d 20 69 6e 20 40 | 63 6f 64 65 7b 61 77 6b |\f} in @|code{awk|
|00005620| 7d 2c 20 61 73 20 69 6e | 20 43 29 20 74 6f 20 73 |}, as in| C) to s|
|00005630| 65 70 61 72 61 74 65 20 | 74 68 65 6d 2c 20 6d 61 |eparate |them, ma|
|00005640| 6b 69 6e 67 20 65 61 63 | 68 20 72 65 63 6f 72 64 |king eac|h record|
|00005650| 0a 58 61 20 70 61 67 65 | 20 6f 66 20 74 68 65 20 |.Xa page| of the |
|00005660| 66 69 6c 65 2e 20 20 54 | 6f 20 64 6f 20 74 68 69 |file. T|o do thi|
|00005670| 73 2c 20 6a 75 73 74 20 | 73 65 74 20 74 68 65 20 |s, just |set the |
|00005680| 76 61 72 69 61 62 6c 65 | 20 40 63 6f 64 65 7b 52 |variable| @code{R|
|00005690| 53 7d 20 74 6f 0a 58 40 | 63 6f 64 65 7b 22 5c 66 |S} to.X@|code{"\f|
|000056a0| 22 7d 20 28 61 20 73 74 | 72 69 6e 67 20 63 6f 6e |"} (a st|ring con|
|000056b0| 74 61 69 6e 69 6e 67 20 | 74 68 65 20 66 6f 72 6d |taining |the form|
|000056c0| 66 65 65 64 20 63 68 61 | 72 61 63 74 65 72 29 2e |feed cha|racter).|
|000056d0| 20 20 41 6e 79 0a 58 6f | 74 68 65 72 20 63 68 61 | Any.Xo|ther cha|
|000056e0| 72 61 63 74 65 72 20 63 | 6f 75 6c 64 20 65 71 75 |racter c|ould equ|
|000056f0| 61 6c 6c 79 20 77 65 6c | 6c 20 62 65 20 75 73 65 |ally wel|l be use|
|00005700| 64 2c 20 61 73 20 6c 6f | 6e 67 20 61 73 20 69 74 |d, as lo|ng as it|
|00005710| 20 77 6f 6e 27 74 20 62 | 65 20 70 61 72 74 0a 58 | won't b|e part.X|
|00005720| 6f 66 20 74 68 65 20 64 | 61 74 61 20 69 6e 20 61 |of the d|ata in a|
|00005730| 20 72 65 63 6f 72 64 2e | 0a 58 0a 58 40 69 67 6e | record.|.X.X@ign|
|00005740| 6f 72 65 0a 58 41 6e 6f | 74 68 65 72 20 74 65 63 |ore.XAno|ther tec|
|00005750| 68 6e 69 71 75 65 20 69 | 73 20 74 6f 20 68 61 76 |hnique i|s to hav|
|00005760| 65 20 62 6c 61 6e 6b 20 | 6c 69 6e 65 73 20 73 65 |e blank |lines se|
|00005770| 70 61 72 61 74 65 20 72 | 65 63 6f 72 64 73 2e 20 |parate r|ecords. |
|00005780| 20 54 68 65 20 73 74 72 | 69 6e 67 0a 58 40 63 6f | The str|ing.X@co|
|00005790| 64 65 7b 22 5e 5c 6e 2b | 22 7d 20 69 73 20 61 20 |de{"^\n+|"} is a |
|000057a0| 72 65 67 75 6c 61 72 20 | 65 78 70 72 65 73 73 69 |regular |expressi|
|000057b0| 6f 6e 20 74 68 61 74 20 | 6d 61 74 63 68 65 73 20 |on that |matches |
|000057c0| 61 6e 79 20 73 65 71 75 | 65 6e 63 65 20 6f 66 0a |any sequ|ence of.|
|000057d0| 58 6e 65 77 6c 69 6e 65 | 73 20 73 74 61 72 74 69 |Xnewline|s starti|
|000057e0| 6e 67 20 61 74 20 74 68 | 65 20 62 65 67 69 6e 6e |ng at th|e beginn|
|000057f0| 69 6e 67 20 6f 66 20 61 | 20 6c 69 6e 65 2d 2d 2d |ing of a| line---|
|00005800| 69 6e 20 6f 74 68 65 72 | 20 77 6f 72 64 73 2c 20 |in other| words, |
|00005810| 69 74 0a 58 6d 61 74 63 | 68 65 73 20 61 20 73 65 |it.Xmatc|hes a se|
|00005820| 71 75 65 6e 63 65 20 6f | 66 20 62 6c 61 6e 6b 20 |quence o|f blank |
|00005830| 6c 69 6e 65 73 2e 20 20 | 49 66 20 79 6f 75 20 73 |lines. |If you s|
|00005840| 65 74 20 40 63 6f 64 65 | 7b 52 53 7d 20 74 6f 20 |et @code|{RS} to |
|00005850| 74 68 69 73 20 73 74 72 | 69 6e 67 2c 0a 58 61 20 |this str|ing,.Xa |
|00005860| 72 65 63 6f 72 64 20 61 | 6c 77 61 79 73 20 65 6e |record a|lways en|
|00005870| 64 73 20 61 74 20 74 68 | 65 20 66 69 72 73 74 20 |ds at th|e first |
|00005880| 62 6c 61 6e 6b 20 6c 69 | 6e 65 20 65 6e 63 6f 75 |blank li|ne encou|
|00005890| 6e 74 65 72 65 64 2e 20 | 20 49 6e 0a 58 61 64 64 |ntered. | In.Xadd|
|000058a0| 69 74 69 6f 6e 2c 20 61 | 20 72 65 67 75 6c 61 72 |ition, a| regular|
|000058b0| 20 65 78 70 72 65 73 73 | 69 6f 6e 20 61 6c 77 61 | express|ion alwa|
|000058c0| 79 73 20 6d 61 74 63 68 | 65 73 20 74 68 65 20 6c |ys match|es the l|
|000058d0| 6f 6e 67 65 73 74 20 70 | 6f 73 73 69 62 6c 65 0a |ongest p|ossible.|
|000058e0| 58 73 65 71 75 65 6e 63 | 65 20 77 68 65 6e 20 74 |Xsequenc|e when t|
|000058f0| 68 65 72 65 20 69 73 20 | 61 20 63 68 6f 69 63 65 |here is |a choice|
|00005900| 2e 20 20 53 6f 20 74 68 | 65 20 6e 65 78 74 20 72 |. So th|e next r|
|00005910| 65 63 6f 72 64 20 64 6f | 65 73 6e 27 74 20 73 74 |ecord do|esn't st|
|00005920| 61 72 74 20 75 6e 74 69 | 6c 0a 58 74 68 65 20 66 |art unti|l.Xthe f|
|00005930| 69 72 73 74 20 6e 6f 6e | 62 6c 61 6e 6b 20 6c 69 |irst non|blank li|
|00005940| 6e 65 20 74 68 61 74 20 | 66 6f 6c 6c 6f 77 73 2d |ne that |follows-|
|00005950| 2d 2d 6e 6f 20 6d 61 74 | 74 65 72 20 68 6f 77 20 |--no mat|ter how |
|00005960| 6d 61 6e 79 20 62 6c 61 | 6e 6b 20 6c 69 6e 65 73 |many bla|nk lines|
|00005970| 0a 58 61 70 70 65 61 72 | 20 69 6e 20 61 20 72 6f |.Xappear| in a ro|
|00005980| 77 2c 20 74 68 65 79 20 | 61 72 65 20 63 6f 6e 73 |w, they |are cons|
|00005990| 69 64 65 72 65 64 20 6f | 6e 65 20 72 65 63 6f 72 |idered o|ne recor|
|000059a0| 64 2d 73 65 70 61 72 61 | 74 6f 72 2e 0a 58 40 65 |d-separa|tor..X@e|
|000059b0| 6e 64 20 69 67 6e 6f 72 | 65 0a 58 0a 58 41 6e 6f |nd ignor|e.X.XAno|
|000059c0| 74 68 65 72 20 74 65 63 | 68 6e 69 71 75 65 20 69 |ther tec|hnique i|
|000059d0| 73 20 74 6f 20 68 61 76 | 65 20 62 6c 61 6e 6b 20 |s to hav|e blank |
|000059e0| 6c 69 6e 65 73 20 73 65 | 70 61 72 61 74 65 20 72 |lines se|parate r|
|000059f0| 65 63 6f 72 64 73 2e 20 | 20 42 79 20 61 20 73 70 |ecords. | By a sp|
|00005a00| 65 63 69 61 6c 0a 58 64 | 69 73 70 65 6e 73 61 74 |ecial.Xd|ispensat|
|00005a10| 69 6f 6e 2c 20 61 20 6e | 75 6c 6c 20 73 74 72 69 |ion, a n|ull stri|
|00005a20| 6e 67 20 61 73 20 74 68 | 65 20 76 61 6c 75 65 20 |ng as th|e value |
|00005a30| 6f 66 20 40 63 6f 64 65 | 7b 52 53 7d 20 69 6e 64 |of @code|{RS} ind|
|00005a40| 69 63 61 74 65 73 20 74 | 68 61 74 0a 58 72 65 63 |icates t|hat.Xrec|
|00005a50| 6f 72 64 73 20 61 72 65 | 20 73 65 70 61 72 61 74 |ords are| separat|
|00005a60| 65 64 20 62 79 20 6f 6e | 65 20 6f 72 20 6d 6f 72 |ed by on|e or mor|
|00005a70| 65 20 62 6c 61 6e 6b 20 | 6c 69 6e 65 73 2e 20 20 |e blank |lines. |
|00005a80| 49 66 20 79 6f 75 20 73 | 65 74 20 40 63 6f 64 65 |If you s|et @code|
|00005a90| 7b 52 53 7d 0a 58 74 6f | 20 74 68 65 20 6e 75 6c |{RS}.Xto| the nul|
|00005aa0| 6c 20 73 74 72 69 6e 67 | 2c 20 61 20 72 65 63 6f |l string|, a reco|
|00005ab0| 72 64 20 61 6c 77 61 79 | 73 20 65 6e 64 73 20 61 |rd alway|s ends a|
|00005ac0| 74 20 74 68 65 20 66 69 | 72 73 74 20 62 6c 61 6e |t the fi|rst blan|
|00005ad0| 6b 20 6c 69 6e 65 0a 58 | 65 6e 63 6f 75 6e 74 65 |k line.X|encounte|
|00005ae0| 72 65 64 2e 20 20 41 6e | 64 20 74 68 65 20 6e 65 |red. An|d the ne|
|00005af0| 78 74 20 72 65 63 6f 72 | 64 20 64 6f 65 73 6e 27 |xt recor|d doesn'|
|00005b00| 74 20 73 74 61 72 74 20 | 75 6e 74 69 6c 20 74 68 |t start |until th|
|00005b10| 65 20 66 69 72 73 74 20 | 6e 6f 6e 62 6c 61 6e 6b |e first |nonblank|
|00005b20| 0a 58 6c 69 6e 65 20 74 | 68 61 74 20 66 6f 6c 6c |.Xline t|hat foll|
|00005b30| 6f 77 73 2d 2d 2d 6e 6f | 20 6d 61 74 74 65 72 20 |ows---no| matter |
|00005b40| 68 6f 77 20 6d 61 6e 79 | 20 62 6c 61 6e 6b 20 6c |how many| blank l|
|00005b50| 69 6e 65 73 20 61 70 70 | 65 61 72 20 69 6e 20 61 |ines app|ear in a|
|00005b60| 20 72 6f 77 2c 20 74 68 | 65 79 0a 58 61 72 65 20 | row, th|ey.Xare |
|00005b70| 63 6f 6e 73 69 64 65 72 | 65 64 20 6f 6e 65 20 72 |consider|ed one r|
|00005b80| 65 63 6f 72 64 2d 73 65 | 70 61 72 61 74 6f 72 2e |ecord-se|parator.|
|00005b90| 0a 58 0a 58 54 68 65 20 | 73 65 63 6f 6e 64 20 73 |.X.XThe |second s|
|00005ba0| 74 65 70 20 69 73 20 74 | 6f 20 73 65 70 61 72 61 |tep is t|o separa|
|00005bb0| 74 65 20 74 68 65 20 66 | 69 65 6c 64 73 20 69 6e |te the f|ields in|
|00005bc0| 20 74 68 65 20 72 65 63 | 6f 72 64 2e 20 20 4f 6e | the rec|ord. On|
|00005bd0| 65 20 77 61 79 20 74 6f | 20 64 6f 0a 58 74 68 69 |e way to| do.Xthi|
|00005be0| 73 20 69 73 20 74 6f 20 | 70 75 74 20 65 61 63 68 |s is to |put each|
|00005bf0| 20 66 69 65 6c 64 20 6f | 6e 20 61 20 73 65 70 61 | field o|n a sepa|
|00005c00| 72 61 74 65 20 6c 69 6e | 65 3a 20 74 6f 20 64 6f |rate lin|e: to do|
|00005c10| 20 74 68 69 73 2c 20 6a | 75 73 74 20 73 65 74 20 | this, j|ust set |
|00005c20| 74 68 65 0a 58 76 61 72 | 69 61 62 6c 65 20 40 63 |the.Xvar|iable @c|
|00005c30| 6f 64 65 7b 46 53 7d 20 | 74 6f 20 74 68 65 20 73 |ode{FS} |to the s|
|00005c40| 74 72 69 6e 67 20 40 63 | 6f 64 65 7b 22 5c 6e 22 |tring @c|ode{"\n"|
|00005c50| 7d 2e 20 20 28 54 68 69 | 73 20 73 69 6d 70 6c 65 |}. (Thi|s simple|
|00005c60| 20 72 65 67 75 6c 61 72 | 0a 58 65 78 70 72 65 73 | regular|.Xexpres|
|00005c70| 73 69 6f 6e 20 6d 61 74 | 63 68 65 73 20 61 20 73 |sion mat|ches a s|
|00005c80| 69 6e 67 6c 65 20 6e 65 | 77 6c 69 6e 65 2e 29 0a |ingle ne|wline.).|
|00005c90| 58 0a 58 41 6e 6f 74 68 | 65 72 20 69 64 65 61 20 |X.XAnoth|er idea |
|00005ca0| 69 73 20 74 6f 20 64 69 | 76 69 64 65 20 65 61 63 |is to di|vide eac|
|00005cb0| 68 20 6f 66 20 74 68 65 | 20 6c 69 6e 65 73 20 69 |h of the| lines i|
|00005cc0| 6e 74 6f 20 66 69 65 6c | 64 73 20 69 6e 20 74 68 |nto fiel|ds in th|
|00005cd0| 65 20 6e 6f 72 6d 61 6c | 0a 58 6d 61 6e 6e 65 72 |e normal|.Xmanner|
|00005ce0| 2e 20 20 54 68 69 73 20 | 68 61 70 70 65 6e 73 20 |. This |happens |
|00005cf0| 62 79 20 64 65 66 61 75 | 6c 74 20 61 73 20 61 20 |by defau|lt as a |
|00005d00| 72 65 73 75 6c 74 20 6f | 66 20 61 20 73 70 65 63 |result o|f a spec|
|00005d10| 69 61 6c 20 66 65 61 74 | 75 72 65 3a 20 77 68 65 |ial feat|ure: whe|
|00005d20| 6e 0a 58 40 63 6f 64 65 | 7b 52 53 7d 20 69 73 20 |n.X@code|{RS} is |
|00005d30| 73 65 74 20 74 6f 20 74 | 68 65 20 6e 75 6c 6c 20 |set to t|he null |
|00005d40| 73 74 72 69 6e 67 2c 20 | 74 68 65 20 6e 65 77 6c |string, |the newl|
|00005d50| 69 6e 65 20 63 68 61 72 | 61 63 74 65 72 20 40 65 |ine char|acter @e|
|00005d60| 6d 70 68 7b 61 6c 77 61 | 79 73 7d 0a 58 61 63 74 |mph{alwa|ys}.Xact|
|00005d70| 73 20 61 73 20 61 20 66 | 69 65 6c 64 20 73 65 70 |s as a f|ield sep|
|00005d80| 61 72 61 74 6f 72 2e 20 | 20 54 68 69 73 20 69 73 |arator. | This is|
|00005d90| 20 69 6e 20 61 64 64 69 | 74 69 6f 6e 20 74 6f 20 | in addi|tion to |
|00005da0| 77 68 61 74 65 76 65 72 | 20 66 69 65 6c 64 0a 58 |whatever| field.X|
|00005db0| 73 65 70 61 72 61 74 69 | 6f 6e 73 20 72 65 73 75 |separati|ons resu|
|00005dc0| 6c 74 20 66 72 6f 6d 20 | 40 63 6f 64 65 7b 46 53 |lt from |@code{FS|
|00005dd0| 7d 2e 0a 58 0a 58 54 68 | 65 20 6f 72 69 67 69 6e |}..X.XTh|e origin|
|00005de0| 61 6c 20 6d 6f 74 69 76 | 61 74 69 6f 6e 20 66 6f |al motiv|ation fo|
|00005df0| 72 20 74 68 69 73 20 73 | 70 65 63 69 61 6c 20 65 |r this s|pecial e|
|00005e00| 78 63 65 70 74 69 6f 6e | 20 77 61 73 20 70 72 6f |xception| was pro|
|00005e10| 62 61 62 6c 79 20 73 6f | 20 74 68 61 74 0a 58 79 |bably so| that.Xy|
|00005e20| 6f 75 20 67 65 74 20 75 | 73 65 66 75 6c 20 62 65 |ou get u|seful be|
|00005e30| 68 61 76 69 6f 72 20 69 | 6e 20 74 68 65 20 64 65 |havior i|n the de|
|00005e40| 66 61 75 6c 74 20 63 61 | 73 65 20 28 69 2e 65 2e |fault ca|se (i.e.|
|00005e50| 2c 20 40 77 7b 40 63 6f | 64 65 7b 46 53 20 3d 3d |, @w{@co|de{FS ==|
|00005e60| 20 22 0a 58 22 7d 7d 29 | 2e 20 20 54 68 69 73 20 | ".X"}})|. This |
|00005e70| 66 65 61 74 75 72 65 20 | 63 61 6e 20 62 65 20 61 |feature |can be a|
|00005e80| 20 70 72 6f 62 6c 65 6d | 20 69 66 20 79 6f 75 20 | problem| if you |
|00005e90| 72 65 61 6c 6c 79 20 64 | 6f 6e 27 74 20 77 61 6e |really d|on't wan|
|00005ea0| 74 20 74 68 65 0a 58 6e | 65 77 6c 69 6e 65 20 63 |t the.Xn|ewline c|
|00005eb0| 68 61 72 61 63 74 65 72 | 20 74 6f 20 73 65 70 61 |haracter| to sepa|
|00005ec0| 72 61 74 65 20 66 69 65 | 6c 64 73 2c 20 73 69 6e |rate fie|lds, sin|
|00005ed0| 63 65 20 74 68 65 72 65 | 20 69 73 20 6e 6f 20 77 |ce there| is no w|
|00005ee0| 61 79 20 74 6f 0a 58 70 | 72 65 76 65 6e 74 20 69 |ay to.Xp|revent i|
|00005ef0| 74 2e 20 20 48 6f 77 65 | 76 65 72 2c 20 79 6f 75 |t. Howe|ver, you|
|00005f00| 20 63 61 6e 20 77 6f 72 | 6b 20 61 72 6f 75 6e 64 | can wor|k around|
|00005f10| 20 74 68 69 73 20 62 79 | 20 75 73 69 6e 67 20 74 | this by| using t|
|00005f20| 68 65 20 40 63 6f 64 65 | 7b 73 70 6c 69 74 7d 0a |he @code|{split}.|
|00005f30| 58 66 75 6e 63 74 69 6f | 6e 20 74 6f 20 62 72 65 |Xfunctio|n to bre|
|00005f40| 61 6b 20 75 70 20 74 68 | 65 20 72 65 63 6f 72 64 |ak up th|e record|
|00005f50| 20 6d 61 6e 75 61 6c 6c | 79 20 28 40 70 78 72 65 | manuall|y (@pxre|
|00005f60| 66 7b 53 74 72 69 6e 67 | 20 46 75 6e 63 74 69 6f |f{String| Functio|
|00005f70| 6e 73 7d 29 2e 0a 58 0a | 58 40 69 67 6e 6f 72 65 |ns})..X.|X@ignore|
|00005f80| 0a 58 48 65 72 65 20 61 | 72 65 20 74 77 6f 20 77 |.XHere a|re two w|
|00005f90| 61 79 73 20 74 6f 20 75 | 73 65 20 72 65 63 6f 72 |ays to u|se recor|
|00005fa0| 64 73 20 73 65 70 61 72 | 61 74 65 64 20 62 79 20 |ds separ|ated by |
|00005fb0| 62 6c 61 6e 6b 20 6c 69 | 6e 65 73 20 61 6e 64 20 |blank li|nes and |
|00005fc0| 62 72 65 61 6b 20 65 61 | 63 68 0a 58 6c 69 6e 65 |break ea|ch.Xline|
|00005fd0| 20 69 6e 74 6f 20 66 69 | 65 6c 64 73 20 6e 6f 72 | into fi|elds nor|
|00005fe0| 6d 61 6c 6c 79 3a 0a 58 | 0a 58 40 65 78 61 6d 70 |mally:.X|.X@examp|
|00005ff0| 6c 65 0a 58 61 77 6b 20 | 27 42 45 47 49 4e 20 40 |le.Xawk |'BEGIN @|
|00006000| 7b 20 52 53 20 3d 20 22 | 22 3b 20 46 53 20 3d 20 |{ RS = "|"; FS = |
|00006010| 22 5b 20 5c 74 5c 6e 5d | 2b 22 20 40 7d 20 40 7b |"[ \t\n]|+" @} @{|
|00006020| 20 70 72 69 6e 74 20 24 | 31 20 40 7d 27 20 42 42 | print $|1 @}' BB|
|00006030| 53 2d 6c 69 73 74 0a 58 | 0a 58 40 65 78 64 65 6e |S-list.X|.X@exden|
|00006040| 74 20 40 72 7b 6f 72 7d | 0a 58 0a 58 61 77 6b 20 |t @r{or}|.X.Xawk |
|00006050| 27 42 45 47 49 4e 20 40 | 7b 20 52 53 20 3d 20 22 |'BEGIN @|{ RS = "|
|00006060| 5e 5c 6e 2b 22 3b 20 46 | 53 20 3d 20 22 5b 20 5c |^\n+"; F|S = "[ \|
|00006070| 74 5c 6e 5d 2b 22 20 40 | 7d 20 40 7b 20 70 72 69 |t\n]+" @|} @{ pri|
|00006080| 6e 74 20 24 31 20 40 7d | 27 20 42 42 53 2d 6c 69 |nt $1 @}|' BBS-li|
|00006090| 73 74 0a 58 40 65 6e 64 | 20 65 78 61 6d 70 6c 65 |st.X@end| example|
|000060a0| 0a 58 40 65 6e 64 20 69 | 67 6e 6f 72 65 0a 58 0a |.X@end i|gnore.X.|
|000060b0| 58 40 69 67 6e 6f 72 65 | 0a 58 48 65 72 65 20 69 |X@ignore|.XHere i|
|000060c0| 73 20 68 6f 77 20 74 6f | 20 75 73 65 20 72 65 63 |s how to| use rec|
|000060d0| 6f 72 64 73 20 73 65 70 | 61 72 61 74 65 64 20 62 |ords sep|arated b|
|000060e0| 79 20 62 6c 61 6e 6b 20 | 6c 69 6e 65 73 20 61 6e |y blank |lines an|
|000060f0| 64 20 62 72 65 61 6b 20 | 65 61 63 68 0a 58 6c 69 |d break |each.Xli|
|00006100| 6e 65 20 69 6e 74 6f 20 | 66 69 65 6c 64 73 20 6e |ne into |fields n|
|00006110| 6f 72 6d 61 6c 6c 79 3a | 0a 58 0a 58 40 65 78 61 |ormally:|.X.X@exa|
|00006120| 6d 70 6c 65 0a 58 61 77 | 6b 20 27 42 45 47 49 4e |mple.Xaw|k 'BEGIN|
|00006130| 20 40 7b 20 52 53 20 3d | 20 22 22 3b 20 46 53 20 | @{ RS =| ""; FS |
|00006140| 3d 20 22 5b 20 5c 74 5c | 6e 5d 2b 22 20 40 7d 20 |= "[ \t\|n]+" @} |
|00006150| 3b 20 40 7b 20 70 72 69 | 6e 74 20 24 31 20 40 7d |; @{ pri|nt $1 @}|
|00006160| 27 20 42 42 53 2d 6c 69 | 73 74 0a 58 40 65 6e 64 |' BBS-li|st.X@end|
|00006170| 20 65 78 61 6d 70 6c 65 | 0a 58 40 65 6e 64 20 69 | example|.X@end i|
|00006180| 67 6e 6f 72 65 0a 58 0a | 58 40 6e 6f 64 65 20 47 |gnore.X.|X@node G|
|00006190| 65 74 6c 69 6e 65 2c 20 | 43 6c 6f 73 65 20 49 6e |etline, |Close In|
|000061a0| 70 75 74 2c 20 4d 75 6c | 74 69 70 6c 65 20 4c 69 |put, Mul|tiple Li|
|000061b0| 6e 65 2c 20 52 65 61 64 | 69 6e 67 20 46 69 6c 65 |ne, Read|ing File|
|000061c0| 73 0a 58 40 73 65 63 74 | 69 6f 6e 20 45 78 70 6c |s.X@sect|ion Expl|
|000061d0| 69 63 69 74 20 49 6e 70 | 75 74 20 77 69 74 68 20 |icit Inp|ut with |
|000061e0| 40 63 6f 64 65 7b 67 65 | 74 6c 69 6e 65 7d 0a 58 |@code{ge|tline}.X|
|000061f0| 0a 58 40 66 69 6e 64 65 | 78 20 67 65 74 6c 69 6e |.X@finde|x getlin|
|00006200| 65 0a 58 40 63 69 6e 64 | 65 78 20 69 6e 70 75 74 |e.X@cind|ex input|
|00006210| 2c 20 65 78 70 6c 69 63 | 69 74 0a 58 40 63 69 6e |, explic|it.X@cin|
|00006220| 64 65 78 20 65 78 70 6c | 69 63 69 74 20 69 6e 70 |dex expl|icit inp|
|00006230| 75 74 0a 58 40 63 69 6e | 64 65 78 20 69 6e 70 75 |ut.X@cin|dex inpu|
|00006240| 74 2c 20 40 63 6f 64 65 | 7b 67 65 74 6c 69 6e 65 |t, @code|{getline|
|00006250| 7d 20 63 6f 6d 6d 61 6e | 64 0a 58 40 63 69 6e 64 |} comman|d.X@cind|
|00006260| 65 78 20 72 65 61 64 69 | 6e 67 20 66 69 6c 65 73 |ex readi|ng files|
|00006270| 2c 20 40 63 6f 64 65 7b | 67 65 74 6c 69 6e 65 7d |, @code{|getline}|
|00006280| 20 63 6f 6d 6d 61 6e 64 | 0a 58 53 6f 20 66 61 72 | command|.XSo far|
|00006290| 20 77 65 20 68 61 76 65 | 20 62 65 65 6e 20 67 65 | we have| been ge|
|000062a0| 74 74 69 6e 67 20 6f 75 | 72 20 69 6e 70 75 74 20 |tting ou|r input |
|000062b0| 66 69 6c 65 73 20 66 72 | 6f 6d 20 40 63 6f 64 65 |files fr|om @code|
|000062c0| 7b 61 77 6b 7d 27 73 20 | 6d 61 69 6e 0a 58 69 6e |{awk}'s |main.Xin|
|000062d0| 70 75 74 20 73 74 72 65 | 61 6d 2d 2d 2d 65 69 74 |put stre|am---eit|
|000062e0| 68 65 72 20 74 68 65 20 | 73 74 61 6e 64 61 72 64 |her the |standard|
|000062f0| 20 69 6e 70 75 74 20 28 | 75 73 75 61 6c 6c 79 20 | input (|usually |
|00006300| 79 6f 75 72 20 74 65 72 | 6d 69 6e 61 6c 29 20 6f |your ter|minal) o|
|00006310| 72 20 74 68 65 0a 58 66 | 69 6c 65 73 20 73 70 65 |r the.Xf|iles spe|
|00006320| 63 69 66 69 65 64 20 6f | 6e 20 74 68 65 20 63 6f |cified o|n the co|
|00006330| 6d 6d 61 6e 64 20 6c 69 | 6e 65 2e 20 20 54 68 65 |mmand li|ne. The|
|00006340| 20 40 63 6f 64 65 7b 61 | 77 6b 7d 20 6c 61 6e 67 | @code{a|wk} lang|
|00006350| 75 61 67 65 20 68 61 73 | 20 61 0a 58 73 70 65 63 |uage has| a.Xspec|
|00006360| 69 61 6c 20 62 75 69 6c | 74 2d 69 6e 20 63 6f 6d |ial buil|t-in com|
|00006370| 6d 61 6e 64 20 63 61 6c | 6c 65 64 20 40 63 6f 64 |mand cal|led @cod|
|00006380| 65 7b 67 65 74 6c 69 6e | 65 7d 20 74 68 61 74 0a |e{getlin|e} that.|
|00006390| 58 63 61 6e 20 62 65 20 | 75 73 65 64 20 74 6f 20 |Xcan be |used to |
|000063a0| 72 65 61 64 20 69 6e 70 | 75 74 20 75 6e 64 65 72 |read inp|ut under|
|000063b0| 20 79 6f 75 72 20 65 78 | 70 6c 69 63 69 74 20 63 | your ex|plicit c|
|000063c0| 6f 6e 74 72 6f 6c 2e 0a | 58 0a 58 54 68 69 73 20 |ontrol..|X.XThis |
|000063d0| 63 6f 6d 6d 61 6e 64 20 | 69 73 20 71 75 69 74 65 |command |is quite|
|000063e0| 20 63 6f 6d 70 6c 65 78 | 20 61 6e 64 20 73 68 6f | complex| and sho|
|000063f0| 75 6c 64 20 40 65 6d 70 | 68 7b 6e 6f 74 7d 20 62 |uld @emp|h{not} b|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.