Table of Contents for
sed & awk, 2nd Edition
Close
Version ebook
/
Retour
sed & awk, 2nd Edition
by Arnold Robbins
Published by O'Reilly Media, Inc., 1997
sed & awk, 2nd Edition
Cover
sed & awk, 2nd Edition
A Note Regarding Supplemental Files
Dedication
Preface
Scope of This Handbook
Availability of sed and awk
Obtaining Example Source Code
Conventions Used in This Handbook
About the Second Edition
Acknowledgments from the First Edition
Comments and Questions
1. Power Tools for Editing
1.1. May You Solve Interesting Problems
1.2. A Stream Editor
1.3. A Pattern-Matching Programming Language
1.4. Four Hurdles to Mastering sed and awk
2. Understanding Basic Operations
2.1. Awk, by Sed and Grep, out of Ed
2.2. Command-Line Syntax
2.3. Using sed
2.4. Using awk
2.5. Using sed and awk Together
3. Understanding Regular Expression Syntax
3.1. That’s an Expression
3.2. A Line-Up of Characters
3.3. I Never Metacharacter I Didn’t Like
4. Writing sed Scripts
4.1. Applying Commands in a Script
4.2. A Global Perspective on Addressing
4.3. Testing and Saving Output
4.4. Four Types of sed Scripts
4.5. Getting to the PromiSed Land
5. Basic sed Commands
5.1. About the Syntax of sed Commands
5.2. Comment
5.3. Substitution
5.4. Delete
5.5. Append, Insert, and Change
5.6. List
5.7. Transform
5.8. Print
5.9. Print Line Number
5.10. Next
5.11. Reading and Writing Files
5.12. Quit
6. Advanced sed Commands
6.1. Multiline Pattern Space
6.2. A Case for Study
6.3. Hold That Line
6.4. Advanced Flow Control Commands
6.5. To Join a Phrase
7. Writing Scripts for awk
7.1. Playing the Game
7.2. Hello, World
7.3. Awk’s Programming Model
7.4. Pattern Matching
7.5. Records and Fields
7.6. Expressions
7.7. System Variables
7.8. Relational and Boolean Operators
7.9. Formatted Printing
7.10. Passing Parameters Into a Script
7.11. Information Retrieval
8. Conditionals, Loops, and Arrays
8.1. Conditional Statements
8.2. Looping
8.3. Other Statements That Affect Flow Control
8.4. Arrays
8.5. An Acronym Processor
8.6. System Variables That Are Arrays
9. Functions
9.1. Arithmetic Functions
9.2. String Functions
9.3. Writing Your Own Functions
10. The Bottom Drawer
10.1. The getline Function
10.2. The close( ) Function
10.3. The system( ) Function
10.4. A Menu-Based Command Generator
10.5. Directing Output to Files and Pipes
10.6. Generating Columnar Reports
10.7. Debugging
10.8. Limitations
10.9. Invoking awk Using the #! Syntax
11. A Flock of awks
11.1. Original awk
11.2. Freely Available awks
11.3. Commercial awks
11.4. Epilogue
12. Full-Featured Applications
12.1. An Interactive Spelling Checker
12.2. Generating a Formatted Index
12.3. Spare Details of the masterindex Program
13. A Miscellany of Scripts
13.1. uutot.awk—Report UUCP Statistics
13.2. phonebill—Track Phone Usage
13.3. combine—Extract Multipart uuencoded Binaries
13.4. mailavg—Check Size of Mailboxes
13.5. adj—Adjust Lines for Text Files
13.6. readsource—Format Program Source Files for troff
13.7. gent—Get a termcap Entry
13.8. plpr—lpr Preprocessor
13.9. transpose—Perform a Matrix Transposition
13.10. m1—Simple Macro Processor
A. Quick Reference for sed
A.1. Command-Line Syntax
A.2. Syntax of sed Commands
A.3. Command Summary for sed
B. Quick Reference for awk
B.1. Command-Line Syntax
B.2. Language Summary for awk
B.3. Command Summary for awk
C. Supplement for Chapter 12
C.1. Full Listing of spellcheck.awk
C.2. Listing of masterindex Shell Script
C.3. Documentation for masterindex
masterindex
C.3.1. Background Details
C.3.2. Coding Index Entries
C.3.3. Output Format
C.3.4. Compiling a Master Index
Index
About the Authors
Colophon
Copyright
sed & awk, 2nd Edition
Table of Contents
A Note Regarding Supplemental Files
Dedication
Preface
Scope of This Handbook
Availability of sed and awk
DOS Versions
Other Sources of Information About sed and awk
Sample Programs
Obtaining Example Source Code
FTP
Ftpmail
BITFTP
UUCP
Conventions Used in This Handbook
About the Second Edition
Acknowledgments from the First Edition
Comments and Questions
1. Power Tools for Editing
1.1. May You Solve Interesting Problems
1.2. A Stream Editor
1.3. A Pattern-Matching Programming Language
1.4. Four Hurdles to Mastering sed and awk
2. Understanding Basic Operations
2.1. Awk, by Sed and Grep, out of Ed
2.2. Command-Line Syntax
2.2.1. Scripting
2.2.2. Sample Mailing List
2.3. Using sed
2.3.1. Specifying Simple Instructions
2.3.1.1. Command garbled
2.3.2. Script Files
2.3.2.1. Saving output
2.3.2.2. Suppressing automatic display of input lines
2.3.2.3. Mixing options (POSIX)
2.3.2.4. Summary of options
2.4. Using awk
2.4.1. Running awk
2.4.2. Error Messages
2.4.3. Summary of Options
2.5. Using sed and awk Together
3. Understanding Regular Expression Syntax
3.1. That’s an Expression
3.2. A Line-Up of Characters
3.2.1. The Ubiquitous Backslash
3.2.2. A Wildcard
3.2.3. Writing Regular Expressions
3.2.4. Character Classes
3.2.4.1. A range of characters
3.2.4.2. Excluding a class of characters
3.2.4.3. POSIX character class additions
3.2.5. Repeated Occurrences of a Character
3.2.6. What’s the Word? Part I
3.2.7. Positional Metacharacters
3.2.7.1. Phrases
3.2.8. A Span of Characters
3.2.9. Alternative Operations
3.2.10. Grouping Operations
3.2.11. What’s the Word? Part II
3.2.12. Your Replacement Is Here
3.2.12.1. The extent of the match
3.2.13. Limiting the Extent
3.3. I Never Metacharacter I Didn’t Like
4. Writing sed Scripts
4.1. Applying Commands in a Script
4.1.1. The Pattern Space
4.2. A Global Perspective on Addressing
4.2.1. Grouping Commands
4.3. Testing and Saving Output
4.3.1. testsed
4.3.2. runsed
4.4. Four Types of sed Scripts
4.4.1. Multiple Edits to the Same File
4.4.2. Making Changes Across a Set of Files
4.4.3. Extracting Contents of a File
4.4.3.1. Extracting a macro definition
4.4.3.2. Generating an outline
4.4.4. Edits To Go
4.5. Getting to the PromiSed Land
5. Basic sed Commands
5.1. About the Syntax of sed Commands
5.2. Comment
5.3. Substitution
5.3.1. Replacement Metacharacters
5.3.1.1. Correcting index entries
5.4. Delete
5.5. Append, Insert, and Change
5.6. List
5.6.1. Stripping Out Non-Printable Characters from nroff Files
5.7. Transform
5.8. Print
5.9. Print Line Number
5.10. Next
5.11. Reading and Writing Files
5.11.1. Checking Out Reference Pages
5.12. Quit
6. Advanced sed Commands
6.1. Multiline Pattern Space
6.1.1. Append Next Line
6.1.1.1. Converting an Interleaf file
6.1.2. Multiline Delete
6.1.3. Multiline Print
6.2. A Case for Study
6.3. Hold That Line
6.3.1. A Capital Transformation
6.3.2. Correcting Index Entries (Part II)
6.3.3. Building Blocks of Text
6.4. Advanced Flow Control Commands
6.4.1. Branching
6.4.2. The Test Command
6.4.3. One More Case
6.5. To Join a Phrase
7. Writing Scripts for awk
7.1. Playing the Game
7.2. Hello, World
7.3. Awk’s Programming Model
7.4. Pattern Matching
7.4.1. Describing Your Script
7.5. Records and Fields
7.5.1. Referencing and Separating Fields
7.5.2. Field Splitting: The Full Story
7.6. Expressions
7.6.1. Averaging Student Grades
7.7. System Variables
7.7.1. Working with Multiline Records
7.7.2. Balance the Checkbook
7.8. Relational and Boolean Operators
7.8.1. Getting Information About Files
7.9. Formatted Printing
7.10. Passing Parameters Into a Script
7.11. Information Retrieval
7.11.1. Finding a Glitch
8. Conditionals, Loops, and Arrays
8.1. Conditional Statements
8.1.1. Conditional Operator
8.2. Looping
8.2.1. While Loop
8.2.2. Do Loop
8.2.3. For Loop
8.2.4. Deriving Factorials
8.3. Other Statements That Affect Flow Control
8.4. Arrays
8.4.1. Associative Arrays
8.4.2. Testing for Membership in an Array
8.4.3. A Glossary Lookup Script
8.4.4. Using split( ) to Create Arrays
8.4.5. Making Conversions
8.4.6. Deleting Elements of an Array
8.5. An Acronym Processor
8.5.1. Multidimensional Arrays
8.6. System Variables That Are Arrays
8.6.1. An Array of Command-Line Parameters
8.6.2. An Array of Environment Variables
9. Functions
9.1. Arithmetic Functions
9.1.1. Trigonometric Functions
9.1.2. Integer Function
9.1.3. Random Number Generation
9.1.4. Pick ‘em
9.2. String Functions
9.2.1. Substrings
9.2.2. String Length
9.2.3. Substitution Functions
9.2.4. Converting Case
9.2.5. The match( ) Function
9.3. Writing Your Own Functions
9.3.1. Writing a Sort Function
9.3.2. Maintaining a Function Library
9.3.3. Another Sorted Example
10. The Bottom Drawer
10.1. The getline Function
10.1.1. Reading Input from Files
10.1.2. Assigning the Input to a Variable
10.1.3. Reading Input from a Pipe
10.2. The close( ) Function
10.3. The system( ) Function
10.4. A Menu-Based Command Generator
10.5. Directing Output to Files and Pipes
10.5.1. Directing Output to a Pipe
10.5.2. Working with Multiple Files
10.6. Generating Columnar Reports
10.7. Debugging
10.7.1. Make a Copy
10.7.2. Before and After Photos
10.7.3. Finding Out Where the Problem Is
10.7.4. Commenting Out Loud
10.7.5. Slash and Burn
10.7.6. Getting Defensive About Your Script
10.8. Limitations
10.9. Invoking awk Using the #! Syntax
11. A Flock of awks
11.1. Original awk
11.1.1. Escape Sequences
11.1.2. Exponentiation
11.1.3. The C Conditional Expression
11.1.4. Variables as Boolean Patterns
11.1.5. Faking Dynamic Regular Expressions
11.1.6. Control Flow
11.1.7. Field Separating
11.1.8. Arrays
11.1.9. The getline Function
11.1.10. Functions
11.1.11. Built-In Variables
11.2. Freely Available awks
11.2.1. Common Extensions
11.2.1.1. Deleting all elements of an array
11.2.1.2. Obtaining individual characters
11.2.1.3. Flushing buffered output
11.2.1.4. Special filenames
11.2.1.5. The nextfile statement
11.2.1.6. Regular expression record separators (gawk and mawk)
11.2.2. Bell Labs awk
11.2.3. GNU awk (gawk)
11.2.3.1. Command line options
11.2.3.2. An awk program search path
11.2.3.3. Line continuation
11.2.3.4. Extended regular expressions
11.2.3.5. Regular expression record terminators
11.2.3.6. Separating fields
11.2.3.7. Additional special files
11.2.3.8. Additional variables
11.2.3.9. Additional functions
11.2.3.10. A general substitution function
11.2.3.11. Time management for programmers
11.2.4. Michael’s awk (mawk)
11.3. Commercial awks
11.3.1. MKS awk
11.3.2. Thompson Automation awk (tawk)
11.3.2.1. Tawk language extensions
11.3.2.2. Additional built-in tawk functions
11.3.3. Videosoft VSAwk
11.4. Epilogue
12. Full-Featured Applications
12.1. An Interactive Spelling Checker
12.1.1. BEGIN Procedure
12.1.2. Main Procedure
12.1.3. END Procedure
12.1.4. Supporting Functions
12.1.5. The spellcheck Shell Script
12.2. Generating a Formatted Index
12.2.1. The masterindex Program
12.2.2. Standardizing Input
12.2.3. Sorting the Entries
12.2.4. Handling Page Numbers
12.2.5. Merging Entries with the Same Keys
12.2.6. Formatting the Index
12.2.6.1. The masterindex shell script
12.3. Spare Details of the masterindex Program
12.3.1. How to Hide a Special Character
12.3.2. Rotating Two Parts
12.3.3. Finding a Replacement
12.3.4. A Function for Reporting Errors
12.3.5. Handling See Also Entries
12.3.6. Alternative Ways to Sort
13. A Miscellany of Scripts
13.1. uutot.awk—Report UUCP Statistics
13.1.1. Program Notes for uutot.awk
13.2. phonebill—Track Phone Usage
13.2.1. Program Notes for phonebill
13.3. combine—Extract Multipart uuencoded Binaries
13.3.1. Program Notes for combine
13.4. mailavg—Check Size of Mailboxes
13.4.1. Program Notes for mailavg
13.5. adj—Adjust Lines for Text Files
13.5.1. Program Notes for adj
13.6. readsource—Format Program Source Files for troff
13.6.1. Program Notes for readsource
13.7. gent—Get a termcap Entry
13.7.1. Program Notes for gent
13.8. plpr—lpr Preprocessor
13.8.1. Program Notes for plpr
13.9. transpose—Perform a Matrix Transposition
13.9.1. Program Notes for transpose
13.10. m1—Simple Macro Processor
13.10.1. Program Notes for m1
A. Quick Reference for sed
A.1. Command-Line Syntax
A.2. Syntax of sed Commands
A.2.1. Pattern Addressing
A.2.2. Regular Expression Metacharacters for sed
A.3. Command Summary for sed
B. Quick Reference for awk
B.1. Command-Line Syntax
B.1.1. Shell Wrapper for Invoking awk
B.2. Language Summary for awk
B.2.1. Records and Fields
B.2.2. Format of a Script
B.2.2.1. Line termination
B.2.2.2. Comments
B.2.3. Patterns
B.2.4. Regular Expressions
B.2.5. Expressions
B.2.5.1. Constants
B.2.5.2. Escape sequences
B.2.5.3. Variables
B.2.5.4. Arrays
B.2.5.5. System variables
B.2.5.6. Operators
B.2.6. Statements and Functions
B.3. Command Summary for awk
B.3.1. Format Expressions Used in printf and sprintf
C. Supplement for Chapter 12
C.1. Full Listing of spellcheck.awk
C.2. Listing of masterindex Shell Script
C.3. Documentation for masterindex
C.3.1. Background Details
C.3.2. Coding Index Entries
C.3.3. Output Format
C.3.4. Compiling a Master Index
Index
About the Authors
Colophon
Copyright