135502
135502
Robbins
download
https://ebookmeta.com/product/gawk-effective-awk-programming-
arnold-d-robbins/
https://ebookmeta.com/product/learning-the-vi-and-vim-
editors-8th-edition-arnold-robbins/
https://ebookmeta.com/product/learning-the-vi-and-vim-
editors-8th-edition-arnold-robbins-elbert-hannah/
https://ebookmeta.com/product/the-awk-programming-language-
addison-wesley-professional-computing-series-2nd-edition-alfred-
aho/
https://ebookmeta.com/product/principles-and-methods-of-social-
research-4th-edition-william-d-crano-marilynn-b-brewer-andrew-
lac/
A Mean Season (Dom Reilly 2) 1st Edition Marshall
Thornton
https://ebookmeta.com/product/a-mean-season-dom-reilly-2-1st-
edition-marshall-thornton/
https://ebookmeta.com/product/the-basic-practice-of-
statistics-7th-edition-moore/
https://ebookmeta.com/product/tegan-and-sara-modern-heartthrobs-
bibliophonic-7-1st-edition-melody-lau/
https://ebookmeta.com/product/elf-napped-a-filthy-dirty-
christmas-1st-edition-abby-knox-2/
https://ebookmeta.com/product/driving-justice-equality-diversity-
and-inclusion-kristina-kohl/
Digital Health Communications 1st Edition Benoit
Cordelier
https://ebookmeta.com/product/digital-health-communications-1st-
edition-benoit-cordelier/
GNU Awk
GAWK: Effective AWK Programming
A User’s Guide for GNU Awk
Edition 5.1
October, 2021
Arnold D. Robbins
“To boldly go where no man has gone before” is a Registered Trademark of Paramount
Pictures Corporation.
Published by:
ISBN 1-882114-28-0
This is Edition 5.1 of GAWK: Effective AWK Programming: A User’s Guide for GNU Awk,
for the 5.1.1 (or later) version of the GNU implementation of AWK.
Permission is granted to copy, distribute and/or modify this document under the terms
of the GNU Free Documentation License, Version 1.3 or any later version published by
the Free Software Foundation; with the Invariant Sections being “GNU General Public
License”, with the Front-Cover Texts being “A GNU Manual”, and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free
Documentation License”.
a. The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU
manual.”
To my parents, for their love, and for the wonderful example they set for me.
To my wife, Miriam, for making me complete.Thank you for building your life together with me.
To our children, Chana, Rivka, Nachum, and Malka, for enrichening our lives in innumerable ways.
i
Short Contents
Foreword to the Third Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Foreword to the Fourth Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
iii
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
History of awk and gawk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
A Rose by Any Other Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Using This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Dark Corners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
The GNU Project and This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
How to Contribute. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.1 How to Use Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.2 Escape Sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.3 Regular Expression Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.3.1 Regexp Operators in awk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.3.2 Some Notes On Interval Expressions . . . . . . . . . . . . . . . . . . . . . . 53
3.4 Using Bracket Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.5 How Much Text Matches? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.6 Using Dynamic Regexps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.7 gawk-Specific Regexp Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.8 Case Sensitivity in Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.9 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5 Printing Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.1 The print Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.2 print Statement Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.3 Output Separators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5.4 Controlling Numeric Output with print . . . . . . . . . . . . . . . . . . . . . . . 96
5.5 Using printf Statements for Fancier Printing . . . . . . . . . . . . . . . . . . 96
5.5.1 Introduction to the printf Statement. . . . . . . . . . . . . . . . . . . . . 96
5.5.2 Format-Control Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.5.3 Modifiers for printf Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.5.4 Examples Using printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.6 Redirecting Output of print and printf . . . . . . . . . . . . . . . . . . . . . 102
5.7 Special Files for Standard Preopened Data Streams . . . . . . . . . . . 104
5.8 Special File names in gawk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.8.1 Accessing Other Open Files with gawk . . . . . . . . . . . . . . . . . . . 106
5.8.2 Special Files for Network Communications . . . . . . . . . . . . . . . 106
5.8.3 Special File name Caveats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.9 Closing Input and Output Redirections . . . . . . . . . . . . . . . . . . . . . . . 106
5.10 Enabling Nonfatal Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
6 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.1 Constants, Variables, and Conversions . . . . . . . . . . . . . . . . . . . . . . . . 113
6.1.1 Constant Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.1.1.1 Numeric and String Constants . . . . . . . . . . . . . . . . . . . . . . 113
6.1.1.2 Octal and Hexadecimal Numbers . . . . . . . . . . . . . . . . . . . . 114
6.1.1.3 Regular Expression Constants. . . . . . . . . . . . . . . . . . . . . . . 115
6.1.2 Using Regular Expression Constants . . . . . . . . . . . . . . . . . . . . . 115
6.1.2.1 Standard Regular Expression Constants . . . . . . . . . . . . . 116
6.1.2.2 Strongly Typed Regexp Constants . . . . . . . . . . . . . . . . . . 117
6.1.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
vi GAWK: Effective AWK Programming
9 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.1 Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.1.1 Calling Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.1.2 Numeric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
9.1.3 String-Manipulation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9.1.3.1 More about ‘\’ and ‘&’ with
sub(), gsub(), and gensub() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
9.1.4 Input/Output Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
9.1.5 Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
9.1.6 Bit-Manipulation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
9.1.7 Getting Type Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
9.1.8 String-Translation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
9.2 User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
9.2.1 Function Definition Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
9.2.2 Function Definition Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
9.2.3 Calling User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 218
9.2.3.1 Writing a Function Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
9.2.3.2 Controlling Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . 218
9.2.3.3 Passing Function Arguments by Value Or by Reference . . 221
9.2.3.4 Other Points About Calling Functions . . . . . . . . . . . . . . 222
9.2.4 The return Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
9.2.5 Functions and Their Effects on Variable Typing . . . . . . . . . . 224
9.3 Indirect Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
9.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Language: Finnish
HOTTENTOTIT
Koulumuistelmia
Kirj.
JALMARI KARA
Helsingissä, Kustannusosakeyhtiö Otava, 1915.
SISÄLLYS:
Esipuhe.
Huviretkellä.
Hottentotit.
Törkeä kepponen.
Kelkkamäessä.
Joululoman alkaessa.
Filosoofin syntymäpäivä.
Monte Carlossa.
Martti Ranta.
Sairaustodistus.
Ylioppilaskirjoitukset.
Ratkaisevat tunnit.
Kevättutkinto.
ESIPUHE.
Jali.
HUVIRETKELLA.
— Kas siinä näet! Eivät taas tule. Ne ovat koko hirtehisiä, olenhan
sen aina sanonut. Pari tuntia istuntoa koko luokalle!
Oli ihana ilma. Taivas oli sees, ja lauha tuuli puhalsi unisesti.
Kahdeksannen luokan pojat makasivat pelastusveneitten peltisillä
suojuskansilla auringonpaisteessa ja olivat "pollea". Joku heistä piti
runollista esitelmää etääntyvästä rannasta, aaltojen liplatuksesta
laivan kylkeä vasten ja veden sinisistä värivivahduksista kaukaisten
saarten välillä. — Pieni laiva kulki hiljaa, sillä kun oli suuri proomu
perässään.
— Kannatetaan!
— Hyvä on, Pelle, että tottelit. Sinä olet aina niin jumalaton.
Pelkäsin, että suututtaisit esimiehemme heti alussa.
Syntyi hiljaisuus.
— No?
— "Nainen katsoi minuun."
Ovelle koputettiin.
— Nöksit!
Monte Carlo oli kuin sullottu poikia täyteen. Isäntä pani lehden
hyllylle. — Antti Jäntti saapui vasta.
— Kas, merkkikauppias! Missä sinä olet viipynyt? Paljonko olet
tänään alaluokilta nylkenyt? huudettiin.
— Toverit! Niin totta kuin ei meissä ole yhtään raitista, niin totta ei
meistä saa tulla ainoatakaan juoppoa. Suurina juhlahetkinä me
tahdomme irtautua arkipäiväisyydestä, sillä mikään inhimillinen ei
meille saa olla vierasta. Mutta me emme koskaan alennu minkään
himon orjiksi! Mikään ei saa tulla meille tavaksi! Olen puhunut.