21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ii<strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>Table of ContentsForeword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3History of awk and gawk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3A Rose by Any Other Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Using This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6The GNU Project and This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7How to Contribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Getting Started with awk . . . . . . . . . . . . . . . . . . . . . 111.1 How to Run awk Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.1.1 One-Shot Throwaway awk Programs . . . . . . . . . . . . . . . . . . . . . . 111.1.2 Running awk Without Input Files . . . . . . . . . . . . . . . . . . . . . . . . 121.1.3 Running Long Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.1.4 Executable awk Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.1.5 Comments in awk Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.1.6 Shell-Quoting Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.1.6.1 Quoting in MS-DOS Batch Files . . . . . . . . . . . . . . . . . . . . . 161.2 Data Files for the Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.3 Some Simple Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171.4 An Example with Two Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191.5 A More Complex Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.6 awk Statements Versus Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211.7 Other Features of awk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221.8 When to Use awk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . 242.1 How to Use Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.2 Escape Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.3 Regular Expression Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272.4 Using Character Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292.5 gawk-Specific Regexp Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.6 Case Sensitivity in Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.7 How Much Text Matches? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.8 Using Dynamic Regexps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.9 Where You Are Makes A Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!