\unnumbchapentry{Foreword}{1}
\unnumbchapentry{Preface}{3}
\unnumbsecentry{History of \command {awk} and \command {gawk}}{0}{3}
\unnumbsecentry{A Rose by Any Other Name}{0}{4}
\unnumbsecentry{Using This Book}{0}{5}
\unnumbsecentry{Typographical Conventions}{0}{6}
\unnumbsecentry{The GNU Project and This Book}{0}{7}
\unnumbsecentry{How to Contribute}{0}{8}
\unnumbsecentry{Acknowledgments}{0}{9}
\chapentry{Getting Started with \command {awk}}{1}{11}
\secentry{How to Run \command {awk} Programs}{1}{1}{11}
\subsecentry{One-Shot Throwaway \command {awk} Programs}{1}{1}{1}{11}
\subsecentry{Running \command {awk} Without Input Files}{1}{1}{2}{12}
\subsecentry{Running Long Programs}{1}{1}{3}{12}
\subsecentry{Executable \command {awk} Programs}{1}{1}{4}{13}
\subsecentry{Comments in \command {awk} Programs}{1}{1}{5}{14}
\subsecentry{Shell-Quoting Issues}{1}{1}{6}{14}
\secentry{Data Files for the Examples}{1}{2}{16}
\secentry{Some Simple Examples}{1}{3}{17}
\secentry{An Example with Two Rules}{1}{4}{18}
\secentry{A More Complex Example}{1}{5}{19}
\secentry{\command {awk} Statements Versus Lines}{1}{6}{20}
\secentry{Other Features of \command {awk}}{1}{7}{22}
\secentry{When to Use \command {awk}}{1}{8}{22}
\chapentry{Regular Expressions}{2}{23}
\secentry{How to Use Regular Expressions}{2}{1}{23}
\secentry{Escape Sequences}{2}{2}{24}
\secentry{Regular Expression Operators}{2}{3}{26}
\secentry{Using Character Lists}{2}{4}{28}
\secentry{\command {gawk}-Specific Regexp Operators}{2}{5}{30}
\secentry{Case Sensitivity in Matching}{2}{6}{31}
\secentry{How Much Text Matches?}{2}{7}{32}
\secentry{Using Dynamic Regexps}{2}{8}{32}
\chapentry{Reading Input Files}{3}{34}
\secentry{How Input Is Split into Records}{3}{1}{34}
\secentry{Examining Fields}{3}{2}{37}
\secentry{Nonconstant Field Numbers}{3}{3}{38}
\secentry{Changing the Contents of a Field}{3}{4}{38}
\secentry{Specifying How Fields Are Separated}{3}{5}{40}
\subsecentry{Using Regular Expressions to Separate Fields}{3}{5}{1}{41}
\subsecentry{Making Each Character a Separate Field}{3}{5}{2}{42}
\subsecentry{Setting \code {FS} from the Command Line}{3}{5}{3}{42}
\subsecentry{Field-Splitting Summary}{3}{5}{4}{44}
\secentry{Reading Fixed-Width Data}{3}{6}{45}
\secentry{Multiple-Line Records}{3}{7}{46}
\secentry{Explicit Input with \code {getline}}{3}{8}{48}
\subsecentry{Using \code {getline} with No Arguments}{3}{8}{1}{49}
\subsecentry{Using \code {getline} into a Variable}{3}{8}{2}{49}
\subsecentry{Using \code {getline} from a File}{3}{8}{3}{50}
\subsecentry{Using \code {getline} into a Variable from a File}{3}{8}{4}{51}
\subsecentry{Using \code {getline} from a Pipe}{3}{8}{5}{51}
\subsecentry{Using \code {getline} into a Variable from a Pipe}{3}{8}{6}{52}
\subsecentry{Using \code {getline} from a Coprocess}{3}{8}{7}{52}
\subsecentry{Using \code {getline} into a Variable from a Coprocess}{3}{8}{8}{53}
\subsecentry{Points to Remember About \code {getline}}{3}{8}{9}{53}
\subsecentry{Summary of \code {getline} Variants}{3}{8}{10}{53}
\chapentry{Printing Output}{4}{54}
\secentry{The \code {print} Statement}{4}{1}{54}
\secentry{Examples of \code {print} Statements}{4}{2}{54}
\secentry{Output Separators}{4}{3}{56}
\secentry{Controlling Numeric Output with \code {print}}{4}{4}{56}
\secentry{Using \code {printf} Statements for Fancier Printing}{4}{5}{57}
\subsecentry{Introduction to the \code {printf} Statement}{4}{5}{1}{57}
\subsecentry{Format-Control Letters}{4}{5}{2}{57}
\subsecentry{Modifiers for \code {printf} Formats}{4}{5}{3}{58}
\subsecentry{Examples Using \code {printf}}{4}{5}{4}{60}
\secentry{Redirecting Output of \code {print} and \code {printf}}{4}{6}{61}
\secentry{Special File Names in \command {gawk}}{4}{7}{64}
\subsecentry{Special Files for Standard Descriptors}{4}{7}{1}{64}
\subsecentry{Special Files for Process-Related Information}{4}{7}{2}{65}
\subsecentry{Special Files for Network Communications}{4}{7}{3}{66}
\subsecentry{Special File Name Caveats}{4}{7}{4}{66}
\secentry{Closing Input and Output Redirections}{4}{8}{67}
\chapentry{Expressions}{5}{70}
\secentry{Constant Expressions}{5}{1}{70}
\subsecentry{Numeric and String Constants}{5}{1}{1}{70}
\subsecentry{Octal and Hexadecimal Numbers}{5}{1}{2}{70}
\subsecentry{Regular Expression Constants}{5}{1}{3}{71}
\secentry{Using Regular Expression Constants}{5}{2}{72}
\secentry{Variables}{5}{3}{73}
\subsecentry{Using Variables in a Program}{5}{3}{1}{73}
\subsecentry{Assigning Variables on the Command Line}{5}{3}{2}{73}
\secentry{Conversion of Strings and Numbers}{5}{4}{74}
\secentry{Arithmetic Operators}{5}{5}{75}
\secentry{String Concatenation}{5}{6}{76}
\secentry{Assignment Expressions}{5}{7}{77}
\secentry{Increment and Decrement Operators}{5}{8}{80}
\secentry{True and False in \command {awk}}{5}{9}{81}
\secentry{Variable Typing and Comparison Expressions}{5}{10}{82}
\secentry{Boolean Expressions}{5}{11}{84}
\secentry{Conditional Expressions}{5}{12}{85}
\secentry{Function Calls}{5}{13}{86}
\secentry{Operator Precedence (How Operators Nest)}{5}{14}{87}
\chapentry{Patterns, Actions, and Variables}{6}{89}
\secentry{Pattern Elements}{6}{1}{89}
\subsecentry{Regular Expressions as Patterns}{6}{1}{1}{89}
\subsecentry{Expressions as Patterns}{6}{1}{2}{89}
\subsecentry{Specifying Record Ranges with Patterns}{6}{1}{3}{91}
\subsecentry{The \code {BEGIN} and \code {END} Special Patterns}{6}{1}{4}{92}
\subsubsecentry{Startup and Cleanup Actions}{6}{1}{4}{1}{92}
\subsubsecentry{Input/Output from \code {BEGIN} and \code {END} Rules}{6}{1}{4}{2}{93}
\subsecentry{The Empty Pattern}{6}{1}{5}{93}
\secentry{Using Shell Variables in Programs}{6}{2}{93}
\secentry{Actions}{6}{3}{94}
\secentry{Control Statements in Actions}{6}{4}{95}
\subsecentry{The \code {if}-\code {else} Statement}{6}{4}{1}{95}
\subsecentry{The \code {while} Statement}{6}{4}{2}{96}
\subsecentry{The \code {do}-\code {while} Statement}{6}{4}{3}{97}
\subsecentry{The \code {for} Statement}{6}{4}{4}{97}
\subsecentry{The \code {break} Statement}{6}{4}{5}{98}
\subsecentry{The \code {continue} Statement}{6}{4}{6}{99}
\subsecentry{The \code {next} Statement}{6}{4}{7}{100}
\subsecentry{Using \command {gawk}'s \code {nextfile} Statement}{6}{4}{8}{101}
\subsecentry{The \code {exit} Statement}{6}{4}{9}{102}
\secentry{Built-in Variables}{6}{5}{102}
\subsecentry{Built-in Variables That Control \command {awk}}{6}{5}{1}{103}
\subsecentry{Built-in Variables That Convey Information}{6}{5}{2}{105}
\subsecentry{Using \code {ARGC} and \code {ARGV}}{6}{5}{3}{108}
\chapentry{Arrays in \command {awk}}{7}{111}
\secentry{Introduction to Arrays}{7}{1}{111}
\secentry{Referring to an Array Element}{7}{2}{112}
\secentry{Assigning Array Elements}{7}{3}{113}
\secentry{Basic Array Example}{7}{4}{113}
\secentry{Scanning All Elements of an Array}{7}{5}{114}
\secentry{The \code {delete} Statement}{7}{6}{115}
\secentry{Using Numbers to Subscript Arrays}{7}{7}{116}
\secentry{Using Uninitialized Variables as Subscripts}{7}{8}{117}
\secentry{Multidimensional Arrays}{7}{9}{117}
\secentry{Scanning Multidimensional Arrays}{7}{10}{119}
\secentry{Sorting Array Values and Indices with \command {gawk}}{7}{11}{119}
\chapentry{Functions}{8}{121}
\secentry{Built-in Functions}{8}{1}{121}
\subsecentry{Calling Built-in Functions}{8}{1}{1}{121}
\subsecentry{Numeric Functions}{8}{1}{2}{122}
\subsecentry{String-Manipulation Functions}{8}{1}{3}{123}
\subsubsecentry{More About \samp {{\tt\rawbackslashxx }} and \samp {&} with \code {sub}, \code {gsub}, and \code {gensub}}{8}{1}{3}{1}{129}
\subsecentry{Input/Output Functions}{8}{1}{4}{132}
\subsecentry{Using \command {gawk}'s Timestamp Functions}{8}{1}{5}{134}
\subsecentry{Bit-Manipulation Functions of \command {gawk}}{8}{1}{6}{139}
\subsecentry{Using \command {gawk}'s String-Translation Functions}{8}{1}{7}{141}
\secentry{User-Defined Functions}{8}{2}{141}
\subsecentry{Function Definition Syntax}{8}{2}{1}{142}
\subsecentry{Function Definition Examples}{8}{2}{2}{143}
\subsecentry{Calling User-Defined Functions}{8}{2}{3}{144}
\subsecentry{The \code {return} Statement}{8}{2}{4}{146}
\subsecentry{Functions and Their Effects on Variable Typing}{8}{2}{5}{147}
\chapentry{Internationalization with \command {gawk}}{9}{148}
\secentry{Internationalization and Localization}{9}{1}{148}
\secentry{GNU \code {gettext}}{9}{2}{148}
\secentry{Internationalizing \command {awk} Programs}{9}{3}{150}
\secentry{Translating \command {awk} Programs}{9}{4}{151}
\subsecentry{Extracting Marked Strings}{9}{4}{1}{152}
\subsecentry{Rearranging \code {printf} Arguments}{9}{4}{2}{152}
\subsecentry{\command {awk} Portability Issues}{9}{4}{3}{153}
\secentry{A Simple Internationalization Example}{9}{5}{154}
\secentry{\command {gawk} Can Speak Your Language}{9}{6}{155}
\chapentry{Advanced Features of \command {gawk}}{10}{157}
\secentry{Allowing Nondecimal Input Data}{10}{1}{157}
\secentry{Two-Way Communications with Another Process}{10}{2}{158}
\secentry{Using \command {gawk} for Network Programming}{10}{3}{159}
\secentry{Using \command {gawk} with BSD Portals}{10}{4}{161}
\secentry{Profiling Your \command {awk} Programs}{10}{5}{161}
\chapentry{Running \command {awk} and \command {gawk}}{11}{165}
\secentry{Invoking \command {awk}}{11}{1}{165}
\secentry{Command-Line Options}{11}{2}{165}
\secentry{Other Command-Line Arguments}{11}{3}{170}
\secentry{The \env {AWKPATH} Environment Variable}{11}{4}{170}
\secentry{Obsolete Options and/or Features}{11}{5}{171}
\secentry{Undocumented Options and Features}{11}{6}{172}
\secentry{Known Bugs in \command {gawk}}{11}{7}{172}
\chapentry{A Library of \command {awk} Functions}{12}{173}
\secentry{Naming Library Function Global Variables}{12}{1}{173}
\secentry{General Programming}{12}{2}{175}
\subsecentry{Implementing \code {nextfile} as a Function}{12}{2}{1}{175}
\subsecentry{Assertions}{12}{2}{2}{176}
\subsecentry{Rounding Numbers}{12}{2}{3}{177}
\subsecentry{The Cliff Random Number Generator}{12}{2}{4}{178}
\subsecentry{Translating Between Characters and Numbers}{12}{2}{5}{179}
\subsecentry{Merging an Array into a String}{12}{2}{6}{180}
\subsecentry{Managing the Time of Day}{12}{2}{7}{181}
\secentry{Data File Management}{12}{3}{182}
\subsecentry{Noting Data File Boundaries}{12}{3}{1}{183}
\subsecentry{Rereading the Current File}{12}{3}{2}{184}
\subsecentry{Checking for Readable Data Files}{12}{3}{3}{185}
\subsecentry{Treating Assignments as File Names}{12}{3}{4}{185}
\secentry{Processing Command-Line Options}{12}{4}{186}
\secentry{Reading the User Database}{12}{5}{190}
\secentry{Reading the Group Database}{12}{6}{194}
\chapentry{Practical \command {awk} Programs}{13}{199}
\secentry{Running the Example Programs}{13}{1}{199}
\secentry{Reinventing Wheels for Fun and Profit}{13}{2}{199}
\subsecentry{Cutting out Fields and Columns}{13}{2}{1}{200}
\subsecentry{Searching for Regular Expressions in Files}{13}{2}{2}{204}
\subsecentry{Printing out User Information}{13}{2}{3}{208}
\subsecentry{Splitting a Large File into Pieces}{13}{2}{4}{210}
\subsecentry{Duplicating Output into Multiple Files}{13}{2}{5}{211}
\subsecentry{Printing Nonduplicated Lines of Text}{13}{2}{6}{213}
\subsecentry{Counting Things}{13}{2}{7}{216}
\secentry{A Grab Bag of \command {awk} Programs}{13}{3}{219}
\subsecentry{Finding Duplicated Words in a Document}{13}{3}{1}{219}
\subsecentry{An Alarm Clock Program}{13}{3}{2}{220}
\subsecentry{Transliterating Characters}{13}{3}{3}{222}
\subsecentry{Printing Mailing Labels}{13}{3}{4}{224}
\subsecentry{Generating Word-Usage Counts}{13}{3}{5}{226}
\subsecentry{Removing Duplicates from Unsorted Text}{13}{3}{6}{227}
\subsecentry{Extracting Programs from Texinfo Source Files}{13}{3}{7}{228}
\subsecentry{A Simple Stream Editor}{13}{3}{8}{231}
\subsecentry{An Easy Way to Use Library Functions}{13}{3}{9}{233}
\appendixentry{The Evolution of the \command {awk} Language}{A}{239}
\secentry{Major Changes Between V7 and SVR3.1}{A}{1}{239}
\secentry{Changes Between SVR3.1 and SVR4}{A}{2}{240}
\secentry{Changes Between SVR4 and POSIX \command {awk}}{A}{3}{240}
\secentry{Extensions in the Bell Laboratories \command {awk}}{A}{4}{241}
\secentry{Extensions in \command {gawk} Not in POSIX \command {awk}}{A}{5}{242}
\secentry{Major Contributors to \command {gawk}}{A}{6}{245}
\appendixentry{Installing \command {gawk}}{B}{247}
\secentry{The \command {gawk} Distribution}{B}{1}{247}
\subsecentry{Getting the \command {gawk} Distribution}{B}{1}{1}{247}
\subsecentry{Extracting the Distribution}{B}{1}{2}{247}
\subsecentry{Contents of the \command {gawk} Distribution}{B}{1}{3}{248}
\secentry{Compiling and Installing \command {gawk} on Unix}{B}{2}{251}
\subsecentry{Compiling \command {gawk} for Unix}{B}{2}{1}{251}
\subsecentry{Additional Configuration Options}{B}{2}{2}{251}
\subsecentry{The Configuration Process}{B}{2}{3}{252}
\secentry{Installation on Other Operating Systems}{B}{3}{252}
\subsecentry{Installing \command {gawk} on an Amiga}{B}{3}{1}{252}
\subsecentry{Installing \command {gawk} on BeOS}{B}{3}{2}{253}
\subsecentry{Installation on PC Operating Systems}{B}{3}{3}{253}
\subsubsecentry{Installing a Prepared Distribution for PC Systems}{B}{3}{3}{1}{254}
\subsubsecentry{Compiling \command {gawk} for PC Operating Systems}{B}{3}{3}{2}{254}
\subsubsecentry{Using \command {gawk} on PC Operating Systems}{B}{3}{3}{3}{255}
\subsubsecentry{Using \command {gawk} In The Cygwin Environment}{B}{3}{3}{4}{257}
\subsecentry{How to Compile and Install \command {gawk} on VMS}{B}{3}{4}{257}
\subsubsecentry{Compiling \command {gawk} on VMS}{B}{3}{4}{1}{257}
\subsubsecentry{Installing \command {gawk} on VMS}{B}{3}{4}{2}{258}
\subsubsecentry{Running \command {gawk} on VMS}{B}{3}{4}{3}{259}
\subsubsecentry{Building and Using \command {gawk} on VMS POSIX}{B}{3}{4}{4}{259}
\secentry{Unsupported Operating System Ports}{B}{4}{259}
\subsecentry{Installing \command {gawk} on the Atari ST}{B}{4}{1}{260}
\subsubsecentry{Compiling \command {gawk} on the Atari ST}{B}{4}{1}{1}{260}
\subsubsecentry{Running \command {gawk} on the Atari ST}{B}{4}{1}{2}{260}
\subsecentry{Installing \command {gawk} on a Tandem}{B}{4}{2}{261}
\secentry{Reporting Problems and Bugs}{B}{5}{262}
\secentry{Other Freely Available \command {awk} Implementations}{B}{6}{263}
\appendixentry{Implementation Notes}{C}{265}
\secentry{Downward Compatibility and Debugging}{C}{1}{265}
\secentry{Making Additions to \command {gawk}}{C}{2}{265}
\subsecentry{Adding New Features}{C}{2}{1}{265}
\subsecentry{Porting \command {gawk} to a New Operating System}{C}{2}{2}{267}
\secentry{Adding New Built-in Functions to \command {gawk}}{C}{3}{268}
\subsecentry{A Minimal Introduction to \command {gawk} Internals}{C}{3}{1}{268}
\subsecentry{Directory and File Operation Built-ins}{C}{3}{2}{271}
\subsubsecentry{Using \code {chdir} and \code {stat}}{C}{3}{2}{1}{271}
\subsubsecentry{C Code for \code {chdir} and \code {stat}}{C}{3}{2}{2}{273}
\subsubsecentry{Integrating the Extensions}{C}{3}{2}{3}{276}
\secentry{Probable Future Extensions}{C}{4}{277}
\appendixentry{Basic Programming Concepts}{D}{279}
\secentry{What a Program Does}{D}{1}{279}
\secentry{Data Values in a Computer}{D}{2}{280}
\secentry{Floating-Point Number Caveats}{D}{3}{281}
\unnumbchapentry{Glossary}{284}
\unnumbchapentry{GNU General Public License}{294}
\unnumbsecentry{Preamble}{13}{294}
\unnumbsecentry{Terms and Conditions for Copying, Distribution and Modification}{13}{295}
\unnumbsecentry{How to Apply These Terms to Your New Programs}{13}{299}
\unnumbchapentry{GNU Free Documentation License}{301}
\unnumbsecentry{ADDENDUM: How to use this License for your documents}{13}{306}
\unnumbchapentry{Index}{307}
