Effective_awk_Programming_4th_Edition.pdf
GAWK:EffectiveAWKProgramming
aUser'sGuidelorgnuawk
Edition4.1
April,2014
Arnoldd.robbins
Toboldlygowherenomanhasgonebefore"isaRegisteredTrademarkofParamount
PicturesCorporatiOn
Publishedby
FreeSoftwareFoundation
51Franklinstreet.FifthFloor
Boston.Ma02110-1301USA
Phone:+1-617-542-5942
Fax:+1-617-5422652
Email:gnu@gnu.org
Url:http://www.gnu.org
ISBN1882114280
Copyright1989,1991,1992,1993,1996-2005,2007,20092014
FreeSoftwareFoundation.Inc
ThisisEdition4.1ofGAWK:EffectiveAWKProgramming:AUser'sGuideforGNUAwk
forthe1.1.1(orlater)versionoftheGNUimplementationofAWK
Permissionisgrantedtocopy,distributeandormodifythisdocumentunderthetermsof
theGNUFreeDocumentationLicense,Version1.3oranylaterversionpublishedbythe
FrccSoftwarcfoundationwiththcinvariantscctionsbcing"GNGcncralpublicliccnsc
theFront-Covertextsbeing(a)(seebelow),andwiththeBack-CoverTextsbeing(b)(see
belowAcopyofthelicenseisincludedinthesectionentitled"GNUFreeDocumentation
License
a.“AGNUManual
b."YouhavethefreedomtocopyandmodifythisgNU
manua
Buyingcopiesfromthe
FSFsupportsitindevelopinggnuandpromotingsoftwarefreedom
ToMiriaTm,Jormakingmecomplele
ToChana,forthejoyyoubringus
ToRivka,fortheexponentialincrease
ToNachum,fortheaddeddimension
ToMalka,forthenewbeginning
Shortcontents
Foreword
Preface
PartI:Theawklanguage
1GettingStartedwithawk
....13
2Runningawkandgawk
27
3RegularExpressions
41
4ReadinginputFile
...53
5PrintingOutput
81
6Expressions..........
7
7Patterns.ActionsandVariables
.119
8Arraysinawk
145
9Functions
...,.,..,,..159
Partll:ProblemSolvingWithawk
10ALibraryofawkFunctions
.....20
11Practicalawkprograms
233
PartIII:MovingBeyondStandardawkWithgawk
12AdvancedFeaturesofgawk
279
13Internationalizationwithgawk
293
4DebuggingawkPrograms
...,,,303
15ArithmeticandArbitraryPrecisionArithmeticwithgawk..319
16WritingExtensionsforgawk
335
PartIV:Appendices
aTheEvolutionoftheawklanguage
391
bInstallinggawk
.407
CImplementationNotes
,425
DBasicProgramming:Concepts
435
ossary
439
GNUGeneralPubliclicense
.......449
GNUFreedocumentationlicense
461
Index
469
TableofContents
Foreword
Preface
·鲁
3
Historyofawkandgawk
4
arosebyanyotherName
4
UsingthisBook
0
TypographicalConventions
7
Darkcorners
7
ThegnUProjectandThisBook
9
Acknowledgments
Partl:Theawklanguage
GettingStartedwithawk
13
1.1Howtorunawkprograms
.13
1.1.1One-ShotThrowawayawkPrograms
13
1.1.2RunningawkWithoutInputFiles
14
1.1.3RunningLongprograms
14
1.1.4Executableawkpros
gram
15
1.1.5Commentsinawkprograms
,,,,16
1.1.6Shell-QuotingIssues
17
1.1.6.1QuotinginMS-WindowsBatchFiles
1.2DataFilesfortheexample
18
1.3SomeSimpleexamples
19
1.4AnExamplewithTwoRules
,21
1.5AMoreComplexexample
22
1.6awkStatementsVersusLines
23
1.7OtherFeaturesofawk
24
1.8Wh
Useawk
24
2Runningawkandgawk
·.····
....27
2.1Invokingawk
27
2.2Command-LineOptions
….27
2.3OtherCommand-LineArguments
33
2.4NamingStandardInput
34
2.5TheEnvironmentVariablesgawkUses
34
2.5.1TheAWKPATHEnvironmentVariable...........34
2.5.2TheAWKLATHEnvironmentvariable
2.5.3OtherEnvironmentVariables
35
2.6gawksExitStatus
37
2.7IncludingOtherFilesIntoYourProgram
37
ivGAWK:EffectiveAWKProgramming
2.8LoadingSharedLibrariesIntoYourProgram
.38
29ObsoleteOptionsand/orfeatures……………39
2.10UndocumentedOptionsandFeatures
∴,.39
3RegularExpressions
3.1HowtoUscRegularExpressions
41
3.2Escapesequences
42
3.3RegularExprcssionOpcrators
44
3.4USingBracketExpressions
47
3.5gawk
ficRegexpOperators
48
3.6CaseSensitivityinMatching
..49
3.7HowMuchTextMatches?
50
3.8UsingDynamicRegexps
51
4ReadingInputFiles
53
4.1HowInputIssplitintoRecords
53
1.2ExaminingFields
56
4.3Nonconstantfieldnumbers
57
4.4ChangingtheContentsofaField...............58
4.5SpecifyingHowFieldsAl
60
4.5.1WhitespaceNormallySeparatesFiclds
61
4.5.2USingRegularExpressionstoSeparateFields
61
4.5.3MakingEachCharacteraSeparateField
鲁鲁春
63
4.5.4SettingFSfromtheCommandline
63
4.5.5MakingTheFullLineBeaSingleField
64
4.5.6Field-SplittingSummary
64
4.6ReadingFixed-WidthData
66
4.7DefiningFieldsByContent
67
4.8Multiple-LineRecords
69
4.9ExplicitInputwithgetline
71
4.9.1UsinggetlinewithNoArguments
72
4.9.2USinggetlineintoavariable
..72
4.9.3U:
ethinefromafile
73
4.9.4UsinggetlineintoaVariablefromaFile∴……73
4.9.5USinggetline[roInaPipe
74
4.9.6UsinggetlineintoaVariablefromaPipe
75
4.9.7UsinggetlineIronaCoprocess
4.9.8UsinggetlineintoaVariablefromaCoprocess.....76
4.9.9PointstoRememberAboutgetline
76
4.9.10SummaryofgetlineVariants
77
4.10ReadingInputWithATimeout
77
4.11DircctoricsOnThcCommandLinc..............79
用户评论