Table of Contents for
sed & awk, 2nd Edition

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition sed & awk, 2nd Edition by Arnold Robbins Published by O'Reilly Media, Inc., 1997
  1. sed & awk, 2nd Edition
  2. Cover
  3. sed & awk, 2nd Edition
  4. A Note Regarding Supplemental Files
  5. Dedication
  6. Preface
  7. Scope of This Handbook
  8. Availability of sed and awk
  9. Obtaining Example Source Code
  10. Conventions Used in This Handbook
  11. About the Second Edition
  12. Acknowledgments from the First Edition
  13. Comments and Questions
  14. 1. Power Tools for Editing
  15. 1.1. May You Solve Interesting Problems
  16. 1.2. A Stream Editor
  17. 1.3. A Pattern-Matching Programming Language
  18. 1.4. Four Hurdles to Mastering sed and awk
  19. 2. Understanding Basic Operations
  20. 2.1. Awk, by Sed and Grep, out of Ed
  21. 2.2. Command-Line Syntax
  22. 2.3. Using sed
  23. 2.4. Using awk
  24. 2.5. Using sed and awk Together
  25. 3. Understanding Regular Expression Syntax
  26. 3.1. That’s an Expression
  27. 3.2. A Line-Up of Characters
  28. 3.3. I Never Metacharacter I Didn’t Like
  29. 4. Writing sed Scripts
  30. 4.1. Applying Commands in a Script
  31. 4.2. A Global Perspective on Addressing
  32. 4.3. Testing and Saving Output
  33. 4.4. Four Types of sed Scripts
  34. 4.5. Getting to the PromiSed Land
  35. 5. Basic sed Commands
  36. 5.1. About the Syntax of sed Commands
  37. 5.2. Comment
  38. 5.3. Substitution
  39. 5.4. Delete
  40. 5.5. Append, Insert, and Change
  41. 5.6. List
  42. 5.7. Transform
  43. 5.8. Print
  44. 5.9. Print Line Number
  45. 5.10. Next
  46. 5.11. Reading and Writing Files
  47. 5.12. Quit
  48. 6. Advanced sed Commands
  49. 6.1. Multiline Pattern Space
  50. 6.2. A Case for Study
  51. 6.3. Hold That Line
  52. 6.4. Advanced Flow Control Commands
  53. 6.5. To Join a Phrase
  54. 7. Writing Scripts for awk
  55. 7.1. Playing the Game
  56. 7.2. Hello, World
  57. 7.3. Awk’s Programming Model
  58. 7.4. Pattern Matching
  59. 7.5. Records and Fields
  60. 7.6. Expressions
  61. 7.7. System Variables
  62. 7.8. Relational and Boolean Operators
  63. 7.9. Formatted Printing
  64. 7.10. Passing Parameters Into a Script
  65. 7.11. Information Retrieval
  66. 8. Conditionals, Loops, and Arrays
  67. 8.1. Conditional Statements
  68. 8.2. Looping
  69. 8.3. Other Statements That Affect Flow Control
  70. 8.4. Arrays
  71. 8.5. An Acronym Processor
  72. 8.6. System Variables That Are Arrays
  73. 9. Functions
  74. 9.1. Arithmetic Functions
  75. 9.2. String Functions
  76. 9.3. Writing Your Own Functions
  77. 10. The Bottom Drawer
  78. 10.1. The getline Function
  79. 10.2. The close( ) Function
  80. 10.3. The system( ) Function
  81. 10.4. A Menu-Based Command Generator
  82. 10.5. Directing Output to Files and Pipes
  83. 10.6. Generating Columnar Reports
  84. 10.7. Debugging
  85. 10.8. Limitations
  86. 10.9. Invoking awk Using the #! Syntax
  87. 11. A Flock of awks
  88. 11.1. Original awk
  89. 11.2. Freely Available awks
  90. 11.3. Commercial awks
  91. 11.4. Epilogue
  92. 12. Full-Featured Applications
  93. 12.1. An Interactive Spelling Checker
  94. 12.2. Generating a Formatted Index
  95. 12.3. Spare Details of the masterindex Program
  96. 13. A Miscellany of Scripts
  97. 13.1. uutot.awk—Report UUCP Statistics
  98. 13.2. phonebill—Track Phone Usage
  99. 13.3. combine—Extract Multipart uuencoded Binaries
  100. 13.4. mailavg—Check Size of Mailboxes
  101. 13.5. adj—Adjust Lines for Text Files
  102. 13.6. readsource—Format Program Source Files for troff
  103. 13.7. gent—Get a termcap Entry
  104. 13.8. plpr—lpr Preprocessor
  105. 13.9. transpose—Perform a Matrix Transposition
  106. 13.10. m1—Simple Macro Processor
  107. A. Quick Reference for sed
  108. A.1. Command-Line Syntax
  109. A.2. Syntax of sed Commands
  110. A.3. Command Summary for sed
  111. B. Quick Reference for awk
  112. B.1. Command-Line Syntax
  113. B.2. Language Summary for awk
  114. B.3. Command Summary for awk
  115. C. Supplement for Chapter 12
  116. C.1. Full Listing of spellcheck.awk
  117. C.2. Listing of masterindex Shell Script
  118. C.3. Documentation for masterindex
  119. masterindex
  120. C.3.1. Background Details
  121. C.3.2. Coding Index Entries
  122. C.3.3. Output Format
  123. C.3.4. Compiling a Master Index
  124. Index
  125. About the Authors
  126. Colophon
  127. Copyright

Index

A note on the digital index

A link in an index entry is displayed as the section title in which that entry appears. Because some sections have multiple index markers, it is not unusual for an entry to have several links to the same section. Clicking on any link will take you directly to the place in the text in which the marker appears.

Symbols

& (ampersand)
&& (logical AND) operator, Relational and Boolean Operators
in replacement text, Substitution, Replacement Metacharacters
* (asterisk)
** (exponentiation) operator, Expressions
**= (assignment) operator, Expressions
*= (assignment) operator, Expressions
as metacharacter, That’s an Expression, Repeated Occurrences of a Character
multiplication operator, Expressions
\ (backslash), Expressions
(see also escape sequences, awk)
\<, \> escape sequences, What’s the Word? Part II, Extended regular expressions
\`, \' escape sequences, Extended regular expressions
character classes and, Character Classes
as metacharacter, A Line-Up of Characters, The Ubiquitous Backslash
in replacement text, Substitution, Replacement Metacharacters
{} (braces)
\{\} metacharacters, A Line-Up of Characters, A Span of Characters
in awk, Awk, by Sed and Grep, out of Ed, Running awk, Conditional Statements
grouping sed commands in, Grouping Commands, About the Syntax of sed Commands
[] (brackets) metacharacters, A Line-Up of Characters, Character Classes
[::] metacharacters, POSIX character class additions
[..] metacharacters, POSIX character class additions
[==] metacharacters, POSIX character class additions
^ (circumflex)
^= (assignment) operator, Expressions
character classes and, A Line-Up of Characters, Excluding a class of characters
exponentiation operator, Expressions
as metacharacter, A Line-Up of Characters, Positional Metacharacters
in multiline pattern space, Append Next Line
: (colon) for labels, Advanced Flow Control Commands
$ (dollar sign)
as end-of-line metacharacter, A Line-Up of Characters, Positional Metacharacters
for last input line, A Global Perspective on Addressing
in multiline pattern space, Append Next Line
$0, $1, $2, ..., Running awk, Referencing and Separating Fields
. (dot) metacharacter, That’s an Expression, A Wildcard, Repeated Occurrences of a Character
= (equal sign)
== (equal to) operator, Relational and Boolean Operators
for printing line numbers, Print Line Number
! (exclamation point), A Global Perspective on Addressing, Pattern Addressing
!= (not equal to) operator, Relational and Boolean Operators
!~ (does not match) operator, Referencing and Separating Fields, Relational and Boolean Operators, Relational and Boolean Operators
branch command versus, Branching
csh and, Four Hurdles to Mastering sed and awk
logical NOT operator, Relational and Boolean Operators
> (greater than sign)
>= (greater than or equal to) operator, Relational and Boolean Operators
for redirection, Saving output, Testing and Saving Output, Directing Output to Files and Pipes
relational operator, Relational and Boolean Operators
- (hyphen)
-= (assignment) operator, Expressions
-- (decrement) operator, Expressions, Expressions
character classes and, A range of charactersA range of characters
subtraction operator, Expressions
< (less than sign)
<= (less than or equal to) operator, Relational and Boolean Operators
relational operator, Relational and Boolean Operators
# for comments, Comment, Describing Your Script, Comments
#n for suppressing output, Comment
#!, invoking awk with, Invoking awk Using the #! Syntax, Shell Wrapper for Invoking awk
( ) (parentheses), Scripting, A Line-Up of Characters, Grouping Operations
with replacing text, Replacement Metacharacters
% (percent sign)
%= (assignment) operator, Expressions
for format specifications, Formatted Printing
modulo operator, Expressions
+ (plus)
+= (assignment) operator, Expressions
++ (increment) operator, Expressions, Expressions
addition operator, Expressions
metacharacter, Pattern Matching
as metacharacter, A Line-Up of Characters, Repeated Occurrences of a Character
? (question mark)
?: (conditional) operator, Conditional Operator, The C Conditional Expression
as metacharacter, A Line-Up of Characters, Repeated Occurrences of a Character
; (semicolon), Specifying Simple Instructions, Running awk, Line termination
(single quotes), Command-Line Syntax, Specifying Simple Instructions
/ (slash)
/= (assignment) operator, Expressions
// as delimiter, Awk, by Sed and Grep, out of Ed, Substitution
division operator, Expressions
in ed commands, Awk, by Sed and Grep, out of Ed
pattern addressing, Awk, by Sed and Grep, out of Ed, Pattern Addressing
~ (match) operator, Referencing and Separating Fields, Relational and Boolean Operators, Relational and Boolean Operators
| (vertical bar)
|| (logical OR) operator, Relational and Boolean Operators
as metacharacter, A Line-Up of Characters, Alternative Operations
piping output with, Directing Output to a Pipe

A

a command (sed), Append, Insert, and Change
abort statement (tawk), Tawk language extensions
acronym processor (example), An Acronym Processor
addition (+) operator, Expressions
addresses, line, Awk, by Sed and Grep, out of Ed, Awk, by Sed and Grep, out of Ed, A Global Perspective on Addressing, A Global Perspective on Addressing, About the Syntax of sed Commands
addressing by pattern, Awk, by Sed and Grep, out of Ed, Pattern Addressing
printing with =, Print Line Number
adj script (example), adj—Adjust Lines for Text Files
alignment of output fields, Formatted Printing
ampersand (&)
&& (logical AND) operator, Relational and Boolean Operators
in replacement text, Substitution, Replacement Metacharacters
anchors, A Line-Up of Characters, Positional Metacharacters
AND (&&) operator, Relational and Boolean Operators
append command (see a command (sed))
ARGC variable, System Variables That Are Arrays
ARGI variable (tawk), Tawk language extensions
ARGIND variable (gawk), Additional variables
ARGV variable, System Variables That Are Arrays
ARGI variable with (tawk), Tawk language extensions
ARGIND variable with (gawk), Additional variables
arithmetic functions, Arithmetic Functions, Functions
arithmetic operators, awk, Expressions
arrays, Arrays, Arrays, Arrays
deleting elements of, Deleting Elements of an Array, Arrays, Deleting all elements of an array
multidimensional, Multidimensional Arrays, Tawk language extensions
parsing strings into elements, Using split( ) to Create Arrays, Obtaining individual characters
sorting elements in (tawk), Tawk language extensions
splitting, Obtaining individual characters
system variables that are, System Variables That Are Arrays
testing for membership in, Testing for Membership in an Array
assigning input to variables, Assigning the Input to a Variable
assignment operators, awk, Expressions
associative arrays, Associative Arrays
asterisk (*)
** (exponentiation) operator, Expressions
**= (assignment) operator, Expressions
*= (assignment) operator, Expressions
as metacharacter, That’s an Expression, Repeated Occurrences of a Character
multiplication operator, Expressions
automatic edits, Edits To Go
awk, A Pattern-Matching Programming Language, Awk, by Sed and Grep, out of Ed, Using awk, Original awk
arrays (see arrays)
built-in functions, Functions
built-in variables, System Variables, Built-In Variables
command-line syntax, Command-Line Syntax, Command-Line Syntax
commands, About the Syntax of sed Commands, Command Summary for awk
(see also under specific command)
documentation for, Other Sources of Information About sed and awk
error messages, Error Messages
escape sequences, Escape sequences
extensions to, Common Extensions
functions (see functions)
invoking with #!, Invoking awk Using the #! Syntax, Shell Wrapper for Invoking awk
limitations to, Limitations
obtaining, Availability of sed and awk
operators, Operators (see operators, awk)
options, Summary of Options
POSIX standards for, Writing Scripts for awk
programming model, Awk’s Programming Model
quick reference, Quick Reference for awk
regular expression metacharacters, Regular Expressions
with sed, Using sed and awk Together
system variables, System variables
versions of, Availability of sed and awk, Bell Labs awk
writing scripts in, Writing Scripts for awk
AWKPATH variable (gawk), An awk program search path

B

b command (sed), Branching
\B escape sequence, Extended regular expressions
backreferences (see numbered replacement strings)
backslash (\), Expressions
(see also escape sequences, awk)
\<, \> escape sequences, What’s the Word? Part II, Extended regular expressions
\`, \' escape sequences, Extended regular expressions
character classes and, Character Classes
as metacharacter, A Line-Up of Characters, The Ubiquitous Backslash
in replacement text, Substitution, Replacement Metacharacters
bang (!) (see exclamation point)
basic regular expressions (BREs), POSIX character class additions
BEGIN pattern, Hello, World
command-line parameters and, Passing Parameters Into a Script
BEGIN procedure, Control Flow
BEGINFILE procedure (tawk), Tawk language extensions
Bell Labs awk, Bell Labs awk
BITFTP, BITFTP
blocks of text, Building Blocks of Text
Boolean operators, awk, Relational and Boolean Operators
variables as Boolean patterns, Variables as Boolean Patterns
braces {}, Pattern Addressing
\{\} metacharacters, A Line-Up of Characters, A Span of Characters
in awk, Awk, by Sed and Grep, out of Ed, Running awk, Conditional Statements
grouping sed commands in, Grouping Commands, About the Syntax of sed Commands
bracket expressions, Character Classes
brackets []
[::] metacharacters, POSIX character class additions
[..] metacharacters, POSIX character class additions
[==] metacharacters, POSIX character class additions
as metacharacters, A Line-Up of Characters, Character Classes
branch command (see b command (sed))
branching, Branching
break statement, Other Statements That Affect Flow Control
breaking lines, Line continuation
BREs (basic regular expressions), POSIX character class additions
buffers, flushing, Flushing buffered output
built-in functions
awk, Functions
gawk, Additional functions
tawk, Additional built-in tawk functions
built-in variables, System Variables, Built-In Variables

C

c command (sed), Append, Insert, and Change
capitalization, converting, Transform, A Capital Transformation, String Functions, Converting Case
case sensitivity, That’s an Expression, Converting Case
(see also capitalization, converting)
character classes for, Character Classes
IGNORECASE variable (gawk), Additional variables
variable names, Expressions
change command (see c command (sed))
character classes, Character Classes
characters
hiding special, How to Hide a Special Character
matching at word start/end, What’s the Word? Part II
measured span of, A Line-Up of Characters, A Span of Characters
metacharacters (see metacharacters)
newline (see newline characters)
range of (see character classes)
space (see space characters)
stripping non-printable nroff, Stripping Out Non-Printable Characters from nroff Files
circumflex (^)
^= (assignment) operator, Expressions
character classes and, A Line-Up of Characters, Excluding a class of characters
exponentiation operator, Expressions
as metacharacter, A Line-Up of Characters, Positional Metacharacters
in multiline pattern space, Append Next Line
close, The close( ) Function
close( ), Working with Multiple Files
closing files/pipes, The close( ) Function, Working with Multiple Files
closure, Repeated Occurrences of a Character
collating symbols, POSIX character class additions
colon (:) for labels, Advanced Flow Control Commands
columns, output as, Generating Columnar Reports
combine script (example), combine—Extract Multipart uuencoded Binaries
“command garbled” message, Command garbled, About the Syntax of sed Commands
command-line options, gawk, Command line options
command-line parameters
array of, An Array of Command-Line Parameters
passing into script, Passing Parameters Into a Script
command-line syntax, Command-Line Syntax, Command-Line Syntax, Command-Line Syntax
commands, Running awk
(see also under specific command)
awk, Command Summary for awk
executing expressions as, The system( ) Function
grouping, Grouping Commands, About the Syntax of sed Commands
menu-based generator (example), A Menu-Based Command Generator
multiple, Running awk
order of, Applying Commands in a Script
sed, Basic sed Commands, Advanced sed Commands, Command Summary for sed
syntax for, Syntax of sed Commands
comments, Comment, Commenting Out Loud, Comments
in awk scripts, Describing Your Script
commercial versions of awk, Commercial awks
comparing
relationship operators for, Relational and Boolean OperatorsRelational and Boolean Operators
strings, The match( ) Function
concatenation, That’s an Expression, Expressions
conditional statements, Conditional Statements, The C Conditional Expression
constants, Constants
constants, hexadecimal (tawk), Tawk language extensions
continue statement, Other Statements That Affect Flow Control
continued lines, Line continuation
converting, Making Conversions
acronym processor (example), An Acronym Processor
case, Converting Case
numbers to strings, System Variables
CONVFMT variable, System Variables, Associative Arrays
copying programs, Make a Copy
cos( ), Trigonometric Functions
counters in for loops, For Loop
cross-referencing scheme, May You Solve Interesting Problems
csh shell, Four Hurdles to Mastering sed and awk, Specifying Simple Instructions
curly braces (see braces)
customizing functions, Writing Your Own Functions

D

d command (ed), Awk, by Sed and Grep, out of Ed
d command (sed), A Global Perspective on Addressing, Delete
H command with, Hold That Line
D command (sed), Delete, Multiline Delete
with P and N commands, Multiline Print
date and time (see time management)
debugging, Debugging
print command with, Print
decrement (--) operator, Expressions, Expressions
defining
functions, Writing Your Own Functions
variables, Expressions
delete command (ed), Awk, by Sed and Grep, out of Ed
delete command (sed) (see d command (sed); D command (sed))
delete statement (awk), Deleting Elements of an Array, Deleting all elements of an array
deleting
array elements, Deleting Elements of an Array, Arrays, Deleting all elements of an array
lines, Awk, by Sed and Grep, out of Ed, Delete, Multiline Delete
delimiters, System Variables, Field Separating
awk, Running awk, Records and Fields, Referencing and Separating Fields, Field Splitting: The Full Story
FIELDWIDTHS variable (gawk), Separating fields
FS variable, Referencing and Separating Fields, System Variables, Obtaining individual characters
OFS variable, System Variables, System Variables
for regular expressions, Awk, by Sed and Grep, out of Ed, Substitution
subscript-component, Multidimensional Arrays
/dev files, Special filenames, Additional special files
diff program, Testing and Saving Output
division (/) operator, Expressions
do loop, Do Loop
documentation, Other Sources of Information About sed and awk
for masterindex script, Documentation for masterindex
dollar sign ($), A Line-Up of Characters
for last input line, A Global Perspective on Addressing
as metacharacter, Positional Metacharacters
in multiline pattern space, Append Next Line
DOS versions of awk, DOS Versions
dot (.) metacharacter, That’s an Expression, A Wildcard, Repeated Occurrences of a Character
dynamic regular expressions, Faking Dynamic Regular Expressions

E

e (constant), Trigonometric Functions
-e option (sed), Specifying Simple Instructions, Mixing options (POSIX)
ed editor, Understanding Basic OperationsAwk, by Sed and Grep, out of Ed
edits, pipelined, Edits To Go
egrep program, Understanding Regular Expression Syntax
else statements (see if statements)
end
of line (see $ (dollar sign))
of word (see \<, \> escape sequences)
END procedure, Control Flow
ENDFILE procedure (tawk), Tawk language extensions
“Ending delimiter missing” error, Command garbled
ENVIRON variable, System Variables That Are Arrays, An Array of Environment Variables
environment variables, An Array of Environment Variables
equal sign (=)
== (equal to) operator, Relational and Boolean Operators
for printing line numbers, Print Line Number
equivalence classes, POSIX character class additions
EREs (extended regular expressions), POSIX character class additions
ERRNO variable (gawk), Additional variables
error messages, Special filenames, A Function for Reporting Errors
awk, Error Messages
“command garbled”, Command garbled, About the Syntax of sed Commands
sed, Command garbled
errors
debugging, Debugging
spelling, finding (example), An Interactive Spelling Checker
ESC character in vi, List
escape sequences, awk, Expressions, Escape Sequences, Escape sequences
escaping (see backslash)
example programs, Sample Programs
exchange command (see x command (sed))
exclamation point (!), A Global Perspective on Addressing
!= (not equal to) operator, Relational and Boolean Operators
!~ (does not match) operator, Referencing and Separating Fields, Relational and Boolean Operators, Relational and Boolean Operators
csh and, Four Hurdles to Mastering sed and awk
logical NOT operator, Relational and Boolean Operators
tilde (~) operator, Referencing and Separating Fields
exit statement, Other Statements That Affect Flow Control
exp( ), Trigonometric Functions
exponentiation, Expressions, Trigonometric Functions, Exponentiation
** operator, Expressions
^ operator, Expressions
expressions, That’s an Expression, Expressions
awk, Expressions
executing as commands, The system( ) Function
regular (see regular expressions)
extended regular expressions (EREs), POSIX character class additions
extensions
common awk, Common Extensions
gawk, GNU awk (gawk)
mawk, Michael’s awk (mawk)
tawk, Thompson Automation awk (tawk)
extent of matching, The extent of the match
extracting file contents, Extracting Contents of a File

F

-f option (awk), Maintaining a Function Library, Command line options
-f option (sed), Command-Line Syntax, Script Files, Mixing options (POSIX)
-F option (awk), Running awk, Referencing and Separating Fields
factorials, Deriving Factorials
faking dynamic regular expressions, Faking Dynamic Regular Expressions
FAQ on awk, Other Sources of Information About sed and awk
fflush( ), Flushing buffered output
field separators (see delimiters)
fields for awk records, Running awk, Records and Fields, Records and Fields
formatting as output, Formatted Printing
NF variable, System Variables, System Variables
FIELDSWIDTHS variable (gawk), Separating fields
File Transfer Protocol (FTP), FTP
files
closing, The close( ) Function, Working with Multiple Files
editing multiple, Making Changes Across a Set of Files
extracting contents from, Extracting Contents of a File
filenames, special, Special filenames
getting information on, Getting Information About Files
Interleaf, converting, Converting an Interleaf fileConverting an Interleaf file
multiple, Working with Multiple Files
multiple edits to, Multiple Edits to the Same File
nextfile statement, The nextfile statement
reading from, Reading and Writing Files, Reading Input from Files
retrieving information from, Information Retrieval
scripts as (see scripts)
search path for, An awk program search path
special gawk, Additional special files
writing to, Saving output, Reading and Writing Files, Directing Output to Files and Pipes
fixed strings, Writing Regular Expressions
flags, Substitution
g (global), Awk, by Sed and Grep, out of Ed, Substitution, Substitution
numeric, Substitution, Substitution
p (print), Substitution, Substitution
w (write), Substitution, Substitution
flow control, Advanced sed Commands, Building Blocks of Text, Control Flow
branching, Branching
d command (sed), Delete
n command, Next
flushing buffers, Flushing buffered output
FNR variable, System Variables, Assigning the Input to a Variable
for loop, For Loop, Associative Arrays
formatting
awk output, Formatted Printing
awk scripts, Format of a Script
index (example program), Generating a Formatted Index
system time, Time management for programmers
FPAT variable (tawk), Tawk language extensions
Free Software Foundation (FSF), Availability of sed and awk
FS variable, Referencing and Separating Fields, Field Splitting: The Full Story, System Variables, Obtaining individual characters
FTP (File Transfer Protocol), FTP
Ftpmail, Ftpmail
function keyword, Writing Your Own Functions
functions, Functions, Statements and Functions
arithmetic, Arithmetic Functions, Functions
built-in
gawk, Additional functions
tawk, Additional built-in tawk functions
creating library of, Maintaining a Function Library
scope control (tawk), Tawk language extensions
string-related, String Functions
time-related (gawk), Time management for programmersTime management for programmers
trigonometric, Trigonometric Functions
user-defined, Writing Your Own Functions

G

g command (ed), Awk, by Sed and Grep, out of Ed
G command (sed), Hold That Line, Correcting Index Entries (Part II)
g flag, Awk, by Sed and Grep, out of Ed, Substitution, Substitution
gawk (GNU awk), Limitations, GNU awk (gawk)
built-in functions, Additional functions
built-in variables, Additional variables
multiple files and, Working with Multiple Files
generating random numbers, Random Number Generation
gensub( ), A general substitution function
gent script, gent—Get a termcap Entry
get command (see G command (sed))
getline function, The getline Function, The getline Function
getline function, A Menu-Based Command Generator
global
addressing, A Global Perspective on Addressing
variables, Writing Your Own Functions
global command (see g command (ed))
glossary program (example), A Glossary Lookup Script
GNU awk (see gawk)
GNU project, Availability of sed and awk
GNU sed, error messages, Command garbled
greater than sign (>)
>= (greater than or equal to) operator, Relational and Boolean Operators
for redirection, Saving output, Testing and Saving Output, Directing Output to Files and Pipes
relational operator, Relational and Boolean Operators
grep utility, Awk, by Sed and Grep, out of Ed, Making Changes Across a Set of Files
gres program, What’s the Word? Part II
grouping operations (see parentheses)
grouping sed commands, Grouping Commands, About the Syntax of sed Commands
gsub( ), String Functions, Substitution Functions, A general substitution function

H

h command (sed), Hold That LineHold That Line, A Capital Transformation
H command, Hold That Line
hexadecimal constants (tawk), Tawk language extensions
hexadecimal numbers, Expressions
hiding special characters, How to Hide a Special Character
hold command, Correcting Index Entries (Part II) (see h command (sed); H command (sed))
hold space, Hold That Line, Hold That Line
(see also pattern space)
hyphen (-)
-= (assignment) operator, Expressions
-- (decrement) operator, Expressions, Expressions
character classes and, A range of charactersA range of characters
subtraction operator, Expressions

I

i command (sed), Append, Insert, and Change
I/O (see input; output)
if statements, Conditional StatementsConditional Statements
IGNORECASE variable (gawk), Additional variables
in operator, Testing for Membership in an Array, Arrays
increment (++) operator, Expressions, Expressions
index( ), String Functions, Substrings
index, array, Arrays, Associative Arrays
index, formatting (example program), Generating a Formatted Index
INIT procedure (tawk), Tawk language extensions
input, Command-Line Syntax
assigning to variables, Assigning the Input to a Variable
getline function, The getline Function
insert command (see i command (sed))
instructions, awk, Running awk
int( ), Integer Function
Interleaf files, converting, Converting an Interleaf fileConverting an Interleaf file

K

Korn shell, DOS Versions

L

l command (sed), List
labels, Advanced Flow Control Commands
length( ), String Functions, String Length
length, string, String Length
less than sign (<)
<= (less than or equal to) operator, Relational and Boolean Operators
relational operator, Relational and Boolean Operators
library of functions, Maintaining a Function Library
limitations to awk, Limitations
limiting the match extent, Limiting the Extent
line addresses, Awk, by Sed and Grep, out of Ed, Awk, by Sed and Grep, out of Ed, A Global Perspective on Addressing, About the Syntax of sed Commands
printing with =, Print Line Number
line editors, Awk, by Sed and Grep, out of Ed
lines
continuing after breaks, Line continuation
deleting, Awk, by Sed and Grep, out of Ed, Delete
matching over multiple, Phrases
matching start/end of, Positional Metacharacters, What’s the Word? Part II
parsing (see parsing)
reading as input, The getline Function
terminating, Line termination
--lint, --lint-old options (gawk), Command line options
list command (see l command (sed))
local variables, Writing Your Own Functions
log( ), Trigonometric Functions
logging, timestamp with, Time management for programmers
logical AND (&&) operator, Relational and Boolean Operators
logical NOT (!) operator, Relational and Boolean Operators
logical OR (||) operator, Relational and Boolean Operators
loops, Awk’s Programming Model, Looping
arrays and, Arrays
main input loop, Awk’s Programming Model
lowercase (see capitalization)
ls command (UNIX), Getting Information About Files

M

m1 script (example), m1—Simple Macro Processor
mailavg script (example), mailavg—Check Size of Mailboxes
main input loop, Awk’s Programming Model
match (~) operator, Referencing and Separating Fields, Relational and Boolean Operators, Relational and Boolean Operators
match( ), String Functions, The match( ) Function
matching (see pattern matching)
math (see arithmetic functions; arithmetic operators; numbers)
mawk (Michael’s awk), Limitations, Michael’s awk (mawk)
membership in arrays, Testing for Membership in an Array
menu-based command generator (example), A Menu-Based Command Generator
metacharacters, Understanding Regular Expression Syntax, A Line-Up of Characters
* (asterisk), That’s an Expression, Repeated Occurrences of a Character
\ (backslash), A Line-Up of Characters, The Ubiquitous Backslash
\{\}, A Line-Up of Characters, A Span of Characters
[] (brackets), A Line-Up of Characters, Character Classes
^ (circumflex), A Line-Up of Characters, Excluding a class of characters
$ (dollar sign), A Line-Up of Characters, Positional Metacharacters
. (dot), That’s an Expression, A Wildcard, Repeated Occurrences of a Character
+ (plus), A Line-Up of Characters, Repeated Occurrences of a Character, Pattern Matching
? (question mark), A Line-Up of Characters, Repeated Occurrences of a Character
| (vertical bar), A Line-Up of Characters, Alternative Operations
awk regular expression, Regular Expressions
inside brackets, Character Classes
replacement, Replacement Metacharacters
sed regular expression, Regular Expression Metacharacters for sed
\< (start of word), What’s the Word? Part II, Extended regular expressions
\> (end of word), What’s the Word? Part II, Extended regular expressions
-mf option (awk), Limitations
Michael’s awk (see mawk)
MKS awk, MKS awk
MKS Toolkit, DOS Versions
modularization, Finding Out Where the Problem Is
modulo (%) operator, Expressions
-mr option (awk), Limitations
multidimensional arrays, Multidimensional Arrays
tawk and, Tawk language extensions
multiline
delete command (see D command (sed))
matching, Phrases
next command (sed) (see N command (sed))
pattern space, Multiline Pattern Space
print command (see P command (sed))
records, awk, Working with Multiline Records
multiple
awk commands, Running awk
character ranges, A range of characters
conditional statements, Conditional Statements
edits to one file, Multiple Edits to the Same File
files, Making Changes Across a Set of Files, Working with Multiple Files
multiplication (*) operator, Expressions

N

n command (sed), Next
N command (sed), Append Next Line
with P and D commands, Multiline Print
\n escape sequence, Append Next Line
-n option (sed), Suppressing automatic display of input lines, Comment
names
filenames, special, Special filenames, Additional special files
script files, Command-Line Syntax
nawk, Awk, by Sed and Grep, out of Ed
nested conditional statements, Conditional Statements
newline characters, A Line-Up of Characters, Positional Metacharacters, Substitution, Line continuation
. (dot) and, A Wildcard
multiline pattern space and, Multiline Pattern Space
ORS variable for, System Variables, Working with Multiline Records
in replacement strings, Replacement Metacharacters
RS variable for, System Variables, Regular expression record separators (gawk and mawk), Tawk language extensions
newsgroup, awk, Other Sources of Information About sed and awk
next command (sed) (see n command (sed); N command (sed))
next statement (awk), Other Statements That Affect Flow Control, The getline Function
(see also getline function)
nextfile statement, The nextfile statement
NF variable, System Variables, System Variables, Assigning the Input to a Variable
non-English characters, POSIX character class additions
NOT (!) operator, Relational and Boolean Operators
NR variable, System Variables, System Variables, Arrays, Assigning the Input to a Variable
nroff, stripping non-printable characters, Stripping Out Non-Printable Characters from nroff Files
numbered replacement strings, Replacement Metacharacters
numbers
arithmetic functions, Arithmetic Functions, Functions
comparing (relationship operators), Relational and Boolean OperatorsRelational and Boolean Operators
converting to strings, System Variables
factorials, Deriving Factorials
hexadecimal, Expressions, Tawk language extensions
limitations on, Limitations
octal, Expressions
output precision, Formatted Printing
random, Random Number Generation
truncating, Integer Function
numeric flags, Substitution, Substitution

O

obtaining
awk source code, Availability of sed and awk
commercial awk versions, MKS awk, Thompson Automation awk (tawk), Videosoft VSAwk
examples, Obtaining Example Source Code
gawk source code, GNU awk (gawk)
mawk source code, Michael’s awk (mawk)
sample programs, Sample Programs
sed source code, Availability of sed and awk
octal numbers, Expressions
octothorpe (#) for comments, Comment, Describing Your Script, Comments
#n for suppressing output, Comment
OFMT variable, System Variables, Formatted Printing
OFS variable, System Variables, System Variables
operators, awk, Operators
arithmetic, Expressions
assignment, Expressions
Boolean, Relational and Boolean Operators
postfix versus prefix, Expressions
relational, Relational and Boolean OperatorsRelational and Boolean Operators
options, Command-Line Syntax, Specifying Simple Instructions
(see also under specific option)
awk, Summary of Options
combining, Mixing options (POSIX)
sed, Summary of options
OR (||) operator, Relational and Boolean Operators
order of operations, That’s an Expression
commands in scripts, Applying Commands in a Script
ORS variable, System Variables, Working with Multiline Records
output, Command-Line Syntax
buffer, flushing, Flushing buffered output
directing to files, Saving output, Directing Output to Files and Pipes
directing to pipes, Directing Output to a Pipe
formatting (awk), Formatted Printing
formatting into columns, Generating Columnar Reports
saving, Testing and Saving Output
suppressing, Suppressing automatic display of input lines, Comment
testing, Testing and Saving Output
to terminal, Special filenames

P

p command (sed), Print
P command (sed), Multiline Print
with N and D commands, Multiline Print
p flag, Substitution, Substitution
parameters, function, Writing Your Own Functions, Writing Your Own Functions
parameters, script, Passing Parameters Into a Script
parentheses ( ), Scripting, A Line-Up of Characters, Grouping Operations
with replacing text, Replacement Metacharacters
parsing, Awk, by Sed and Grep, out of Ed
referencing fields, Running awk, Referencing and Separating Fields
strings into array elements, Using split( ) to Create Arrays, Obtaining individual characters
pattern addressing, Awk, by Sed and Grep, out of Ed, Pattern Addressing
pattern matching, A Pattern-Matching Programming Language, Four Hurdles to Mastering sed and awk, Scripting
(see also regular expressions)
in awk, Pattern Matching
closure, Repeated Occurrences of a Character
extent of match, The extent of the match
fixed strings, Writing Regular Expressions
metacharacters for (see metacharacters)
over multiple lines, Phrases
phrases, Phrases
at start/end of words, What’s the Word? Part II
pattern space, The Pattern Space, Hold That Line
(see also hold space)
deleting contents of (see d command (sed))
displaying (see l command (sed))
inputing file into (see reading from files)
insert and append commands and, Append, Insert, and Change
multiline, Multiline Pattern Space
patterns, Awk, by Sed and Grep, out of Ed, Scripting, Patterns
PCs, DOS Versions
percent sign (%)
%= (assignment) operator, Expressions
for format specifications, Formatted Printing
modulo operator, Expressions
phonebill script (example), phonebill—Track Phone Usage
phrase script (example), To Join a Phrase
phrases, Phrases
pipelined edits, Edits To Go
pipes
closing, The close( ) Function
directing output to, Directing Output to a Pipe
limitations on, Limitations
reading input from, Reading Input from a Pipe
plpr script (example), plpr—lpr Preprocessor
plus (+)
+= (assignment) operator, Expressions
++ (increment) operator, Expressions, Expressions
addition operator, Expressions
metacharacter, Pattern Matching
as metacharacter, A Line-Up of Characters, Repeated Occurrences of a Character
positional metacharacters, Positional Metacharacters
POSIX
awk (see awk)
character class additions, Excluding a class of characters, Regular Expressions
character classes standard, POSIX character class additionsPOSIX character class additions
option conbinations, standard for, Mixing options (POSIX)
regular expressions standard, POSIX character class additionsPOSIX character class additions
standard for labels, Advanced Flow Control Commands
--posix option (gawk), Command line options
postfix operators, Expressions
precedence, operation, That’s an Expression, Operators
precision modifier, Formatted Printing
prefix operators, Expressions
print command (sed) (see p command; P command)
print statement (awk), Awk, by Sed and Grep, out of Ed, Hello, World, Directing Output to Files and Pipes
printerr( ), Special filenames, A Function for Reporting Errors
printf statement, Formatted Printing, Directing Output to Files and Pipes
printing
formatting output (awk), Formatted Printing
line addresses with =, Print Line Number
procedures, Scripting, Running awk
PROCINFO array (gawk), Additional special files
programming
awk, model for, Awk’s Programming Model
sed, tips for, Getting to the PromiSed Land
prompts, Awk, by Sed and Grep, out of Ed

Q

q command (sed), QuitQuit
question mark (?)
?: (conditional) operator, Conditional Operator, The C Conditional Expression
as metacharacter, A Line-Up of Characters, Repeated Occurrences of a Character
quit command (see q command (sed))
quotation marks (?), Command-Line Syntax, Specifying Simple Instructions

R

r command (sed), Reading and Writing Files
rand( ), Random Number Generation
random numbers, Random Number Generation
range of characters (see character classes)
--re-interval option (gawk), Command line options
read command (see r command (sed))
reading, The getline Function
from files, Reading and Writing Files, Reading Input from Files
from pipe, Reading Input from a Pipe
readsource script (example), readsource—Format Program Source Files for troff
RECLEN variable (tawk), Tawk language extensions
records, awk, Running awk, Records and Fields, Records and Fields
arrays and, Arrays
fixed-length (tawk), Tawk language extensions
multiline, Working with Multiline Records
NF variable, System Variables, System Variables
NR variable, System Variables, System Variables, Arrays, Assigning the Input to a Variable
RT variable (gawk), Regular expression record terminators
separators for (see delimiters)
redirection, Saving output, Testing and Saving Output, Directing Output to Files and Pipes
references, Other Sources of Information About sed and awk
referencing fields, Running awk, Referencing and Separating Fields
regular expressions, Four Hurdles to Mastering sed and awk, Four Hurdles to Mastering sed and awk, Understanding Regular Expression Syntax, Patterns, Regular Expressions
(see also pattern matching)
as constants, Relational and Boolean Operators
delimiters for, Awk, by Sed and Grep, out of Ed, Substitution
dynamic, faking, Faking Dynamic Regular Expressions
ed and, Awk, by Sed and Grep, out of Ed
examples of, I Never Metacharacter I Didn’t Like
gawk extensions to, Extended regular expressions
metacharacters for (see netacharacters)
POSIX standard for, POSIX character class additionsPOSIX character class additions
RS variable as, Regular expression record separators (gawk and mawk), Tawk language extensions
tawk and, Tawk language extensions
union of, A Line-Up of Characters, Alternative Operations
writing, Writing Regular Expressions
relational expressions, Patterns
relational operators, Relational and Boolean OperatorsRelational and Boolean Operators
replacement metacharacters, Replacement Metacharacters
numbered saves, Replacement Metacharacters
replacing text, A Stream Editor, The extent of the match
retrieving data from files, Information Retrieval
return statement, Writing Your Own Functions, Writing a Sort Function
revision control systems, Make a Copy
RS variable, System Variables
regular expression for, Regular expression record separators (gawk and mawk), Tawk language extensions
RT variable (gawk), Regular expression record terminators
rules, pattern-matching (see pattern matching)

S

s command (ed), Awk, by Sed and Grep, out of Ed
s command (sed), Substitution
sample programs, Sample Programs
saving output, Saving output, Testing and Saving Output, Directing Output to Files and Pipes
scope control (tawk), Tawk language extensions
scripts, Awk, by Sed and Grep, out of Ed, Command-Line Syntax, Scripting, Shell Wrapper for Invoking awk
debugging, Debugging
examples of, A Miscellany of Scripts
as files, Script Files
format of, Format of a Script
modularizing, Finding Out Where the Problem Is
names for, Command-Line Syntax
passing parameters to, Passing Parameters Into a Script
phrase (example script), To Join a PhraseTo Join a Phrase
stopping, sed (see q command (sed))
search path for awk files, An awk program search path
search-and-replace, A Stream Editor
matching extent, The extent of the match
sed, A Stream Editor, Using sed
with awk, Using sed and awk Together
command-line syntax, Command-Line Syntax, Command-Line Syntax
commands, Basic sed Commands, About the Syntax of sed Commands, Advanced sed Commands
(see also under specific command)
syntax of, About the Syntax of sed Commands
commands for, Command Summary for sed
documentation for, Other Sources of Information About sed and awk
ed versus, Awk, by Sed and Grep, out of Ed
error messages, Command garbled
obtaining, Availability of sed and awk
options, Specifying Simple Instructions, Summary of options
(see also under specific option)
programming tips for, Getting to the PromiSed Land
quick reference, Command-Line Syntax
regular expression metacharacters, Regular Expression Metacharacters for sed
semicolon (;), Specifying Simple Instructions, Running awk, Line termination
shell scripts (see scripts)
shells, Four Hurdles to Mastering sed and awk, Four Hurdles to Mastering sed and awk, Specifying Simple Instructions
(see also under specific shell name)
sin( ), Trigonometric Functions
single quotation marks (?), Command-Line Syntax, Specifying Simple Instructions
slash (/)
/= (assignment) operator, Expressions
// as delimiter, Awk, by Sed and Grep, out of Ed, Substitution
division operator, Expressions
in ed commands, Awk, by Sed and Grep, out of Ed
sort function (example), Writing a Sort Function, Another Sorted Example
sort program, Using sed and awk Together
sorting array elements (tawk), Tawk language extensions
source code, obtaining (see obtaining)
--source option (gawk), Command line options
space characters, Specifying Simple Instructions, About the Syntax of sed Commands
as awk delimiters, Running awk, Field Splitting: The Full Story
as string concatenator, Expressions
span, character, A Line-Up of Characters, A Span of Characters
special characters, Specifying Simple Instructions, Understanding Regular Expression Syntax
(see also escape sequences, awk; metacharacters)
special filenames, Special filenames, Additional special files
spell checker program (example), An Interactive Spelling Checker
split( ), Using split( ) to Create Arrays, String Functions, Obtaining individual characters
sprintf( ), String Functions, String Functions
sqrt( ), Trigonometric Functions
srand( ), Random Number Generation
standard input/output, Command-Line Syntax
start
of line (see ^ (circumflex))
of word (see \<, \> escape sequences)
statements, awk, Statements and Functions
stopping sed scripts (see q command (sed))
stream editor, A Stream Editor, Awk, by Sed and Grep, out of Ed, Edits To Go
strftime( ), Time management for programmers
strings, That’s an Expression, Expressions
comparing, The match( ) Function
concatenating, Expressions
converting from numbers, System Variables
fixed (see fixed strings)
functions for, String Functions
length of, String Length
limitations on, Limitations
parsing into array elements, Using split( ) to Create Arrays, Obtaining individual characters
substitution functions (awk), Substitution Functions, A general substitution function
substrings, Substrings
stripping non-printable characters, Stripping Out Non-Printable Characters from nroff Files
sub( ), String Functions, Substitution Functions, A general substitution function
SUBSEP variable, Multidimensional Arrays
substitute command (see s command)
substituting text (sed), Awk, by Sed and Grep, out of Ed, Substitution, Substitution
(see also s command (sed))
relacement metacharacters, Replacement Metacharacters
substitution functions (awk), Substitution Functions, A general substitution function
substr( ), String Functions, Substrings, Obtaining individual characters
substrings (see strings)
subtraction (-) operator, Expressions
suppressing output, Suppressing automatic display of input lines, Comment
syntax
command-line, Command-Line Syntax, Command-Line Syntax, Command-Line Syntax
sed commands, About the Syntax of sed Commands
system( ), The system( ) Function
system time, Time management for programmers
system variables, System Variables, System Variables That Are Arrays, System variables
gawk, Additional variables
systime( ), Time management for programmers

T

t command (sed), The Test Command
tawk, Thompson Automation awk (tawk)
terminal, user, Special filenames
terminating lines, Line termination
terminator, record, Regular expression record terminators
test command (see t command (sed))
testing
for membership in arrays, Testing for Membership in an Array
output, Testing and Saving Output
text blocks, Building Blocks of Text
Thompson Automation awk (tawk), Thompson Automation awk (tawk)
tilde (~) operator, Referencing and Separating Fields, Relational and Boolean Operators, Relational and Boolean Operators
time management, Time management for programmersTime management for programmers
tolower( ), String Functions, Converting Case
toupper( ), String Functions, Converting Case
--traditional option (gawk), Command line options
transform command (see y command (sed))
transpose script (example), transpose—Perform a Matrix Transposition
trigonometric functions, Trigonometric Functions
truncating numbers, Integer Function

U

union metacharacter, lack of, Alternative Operations
union of regular expressions, A Line-Up of Characters, Alternative Operations
uppercase (see capitalization)
user-defined functions, Writing Your Own Functions
UUCP, UUCP
uutot.awk script (example), uutot.awk—Report UUCP Statistics

V

-v option (awk), Passing Parameters Into a Script, A Menu-Based Command Generator
variables, Expressions, Variables
arrays (see arrays)
assigning input to, Assigning the Input to a Variable
as Boolean patterns, Variables as Boolean Patterns
built-in, System Variables, Built-In Variables
gawk, Additional variables
environment, An Array of Environment Variables
local vs. global, Writing Your Own Functions
scope control (tawk), Tawk language extensions
system (see system variables)
verifying (see testing)
versions, awk, Availability of sed and awk, Original awk, Bell Labs awk
vertical bar (|)
as metacharacter, A Line-Up of Characters, Alternative Operations
piping output with, Directing Output to a Pipe
vi editor, List, List
Videosoft VSAwk, Videosoft VSAwk
Visual Basic, awk for, Videosoft VSAwk

W

w command (sed), Reading and Writing Files
\w escape sequence, Extended regular expressions
\W escape sequence, Extended regular expressions
w flag, Substitution, Substitution
while loop, While Loop
whitespace (see space characters)
width, output field, Formatted Printing
wildcard metacharacter (see . (dot))
write command (see w command (sed))
writing
from files, Reading and Writing Files
to files, Saving output, Reading and Writing Files, Directing Output to Files and Pipes
regular expressions, Writing Regular Expressions
scripts, Four Hurdles to Mastering sed and awk
awk, Writing Scripts for awk
sed, Writing sed Scripts
user-defined functions, Writing Your Own Functions

Y

y command (sed), Transform
\y escape sequence, Extended regular expressions