Tải bản đầy đủ (.pdf) (602 trang)

Effective awk programming universal text processing and pattern matching arnold robbins

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.14 MB, 602 trang )



EffectiveawkProgramming
ArnoldRobbins


Tomyparents,fortheirlove,andforthewonderfulexampletheysetforme.
TomywifeMiriam,formakingmecomplete.Thankyouforbuildingyourlifetogether
withme.
ToourchildrenChana,Rivka,Nachum,andMalka,forenricheningourlivesin
innumerableways.



ForewordtotheThirdEdition
MichaelBrennan
Authorofmawk
ArnoldRobbinsandIaregoodfriends.Wewereintroducedin1990bycircumstances—
andourfavoriteprogramminglanguage,awk.Thecircumstancesstartedacoupleofyears
earlier.IwasworkingatanewjobandnoticedanunpluggedUnixcomputersittinginthe
corner.Nooneknewhowtouseit,andneitherdidI.However,acoupleofdayslater,it
wasrunning,andIwasrootandtheone-and-onlyuser.Thatday,Ibeganthetransition
fromstatisticiantoUnixprogrammer.
OnoneofmanytripstothelibraryorbookstoreinsearchofbooksonUnix,Ifoundthe
grayawkbook,a.k.a.AlfredV.Aho,BrianW.Kernighan,andPeterJ.Weinberger’sThe
AWKProgrammingLanguage(Addison-Wesley,1988).awk’ssimpleprogramming
paradigm—findapatternintheinputandthenperformanaction—oftenreduced
complexortediousdatamanipulationstoafewlinesofcode.Iwasexcitedtotrymyhand
atprogramminginawk.
Alas,theawkonmycomputerwasalimitedversionofthelanguagedescribedinthegray
book.Idiscoveredthatmycomputerhad“oldawk”andthebookdescribed“newawk.”I


learnedthatthiswastypical;theoldversionrefusedtostepasideorrelinquishitsname.If
asystemhadanewawk,itwasinvariablycallednawk,andfewsystemshadit.Thebest
waytogetanewawkwastoftpthesourcecodeforgawkfromprep.ai.mit.edu.gawk
wasaversionofnewawkwrittenbyDavidTruemanandArnold,andavailableunderthe
GNUGeneralPublicLicense.
(Incidentally,it’snolongerdifficulttofindanewawk.gawkshipswithGNU/Linux,and
youcandownloadbinariesorsourcecodeforalmostanysystem;mywifeusesgawkon
herVMSbox.)
MyUnixsystemstartedoutunpluggedfromthewall;itcertainlywasnotpluggedintoa
network.So,oblivioustotheexistenceofgawkandtheUnixcommunityingeneral,and
desiringanewawk,Iwrotemyown,calledmawk.BeforeIwasfinished,Iknewabout
gawk,butitwastoolatetostop,soIeventuallypostedtoacomp.sourcesnewsgroup.
Afewdaysaftermyposting,IgotafriendlyemailfromArnoldintroducinghimself.He
suggestedwesharedesignandalgorithmsandattachedadraftofthePOSIXstandardso
thatIcouldupdatemawktosupportlanguageextensionsaddedafterpublicationofThe
AWKProgrammingLanguage.
Frankly,ifourroleshadbeenreversed,Iwouldnothavebeensoopenandweprobably
wouldhavenevermet.I’mgladwedidmeet.Heisanawkexpert’sawkexpertanda
genuinelyniceperson.Arnoldcontributessignificantamountsofhisexpertiseandtimeto
theFreeSoftwareFoundation.
Thisbookisthegawkreferencemanual,butatitscoreitisabookaboutawkprogramming
thatwillappealtoawideaudience.Itisadefinitivereferencetotheawklanguageas
definedbythe1987BellLaboratoriesreleaseandcodifiedinthe1992POSIXUtilities


standard.
Ontheotherhand,thenoviceawkprogrammercanstudyawealthofpracticalprograms
thatemphasizethepowerofawk’sbasicidioms:data-drivencontrolflow,patternmatching
withregularexpressions,andassociativearrays.Thoselookingforsomethingnewcantry
outgawk’sinterfacetonetworkprotocolsviaspecial/inetfiles.

Theprogramsinthisbookmakeclearthatanawkprogramistypicallymuchsmallerand
fastertodevelopthanacounterpartwritteninC.Consequently,thereisoftenapayoffto
prototypinganalgorithmordesigninawktogetitrunningquicklyandexposeproblems
early.Often,theinterpretedperformanceisadequateandtheawkprototypebecomesthe
product.
Thenewpgawk(profilinggawk)producesprogramexecutioncounts.Irecently
experimentedwithanalgorithmthatfornlinesofinputexhibited∼Cn2performance,
whiletheorypredicted∼Cnlognbehavior.Afewminutesporingovertheawkprof.out
profilepinpointedtheproblemtoasinglelineofcode.pgawkisawelcomeadditiontomy
programmer’stoolbox.
Arnoldhasdistilledoveradecadeofexperiencewritingandusingawkprograms,and
developinggawk,intothisbook.Ifyouuseawkorwanttolearnhow,thenreadthisbook.



ForewordtotheFourthEdition
MichaelBrennan
Authorofmawk
Somethingsdon’tchange.ThirteenyearsagoIwrote:“Ifyouuseawkorwanttolearn
how,thenreadthisbook.”Truethen,andstilltruetoday.
Learningtouseaprogramminglanguageisaboutmorethanmasteringthesyntax.One
needstoacquireanunderstandingofhowtousethefeaturesofthelanguagetosolve
practicalprogrammingproblems.Afocusofthisbookismanyexamplesthatshowhowto
useawk.
Somethingsdochange.Ourcomputersaremuchfasterandhavemorememory.
Consequently,speedandstorageinefficienciesofahigh-levellanguagematterless.
PrototypinginawkandthenrewritinginCforperformancereasonshappensless,because
moreoftentheprototypeisfastenough.
Ofcourse,therearecomputingoperationsthatarebestdoneinCorC++.Withgawk4.1
andlater,youdonothavetochoosebetweenwritingyourprograminawkorinC/C++.

YoucanwritemostofyourprograminawkandtheaspectsthatrequireC/C++capabilities
canbewritteninC/C++,andthenthepiecesgluedtogetherwhenthegawkmoduleloads
theC/C++moduleasadynamicplug-in.Chapter16hasallthedetails,and,asexpected,
manyexamplestohelpyoulearntheinsandouts.
Ienjoyprogramminginawkandhadfun(re)readingthisbook.Ithinkyouwill,too.



Preface
ArnoldRobbins
NofAyalon
Israel
Severalkindsoftasksoccurrepeatedlywhenworkingwithtextfiles.Youmightwantto
extractcertainlinesanddiscardtherest.Oryoumayneedtomakechangeswherever
certainpatternsappear,butleavetherestofthefilealone.Suchjobsareofteneasywith
awk.Theawkutilityinterpretsaspecial-purposeprogramminglanguagethatmakesiteasy
tohandlesimpledata-reformattingjobs.
TheGNUimplementationofawkiscalledgawk;ifyouinvokeitwiththeproperoptionsor
environmentvariables,itisfullycompatiblewiththePOSIX[1]specificationoftheawk
languageandwiththeUnixversionofawkmaintainedbyBrianKernighan.Thismeans
thatallproperlywrittenawkprogramsshouldworkwithgawk.Somostofthetime,we
don’tdistinguishbetweengawkandotherawkimplementations.
Usingawkyoucan:
Managesmall,personaldatabases
Generatereports
Validatedata
Produceindexesandperformotherdocument-preparationtasks
Experimentwithalgorithmsthatyoucanadaptlatertoothercomputerlanguages
Inaddition,gawkprovidesfacilitiesthatmakeiteasyto:
Extractbitsandpiecesofdataforprocessing

Sortdata
Performsimplenetworkcommunications
Profileanddebugawkprograms
ExtendthelanguagewithfunctionswritteninCorC++
Thisbookteachesyouabouttheawklanguageandhowyoucanuseiteffectively.You
shouldalreadybefamiliarwithbasicsystemcommands,suchascatandls,[2]aswellas
basicshellfacilities,suchasinput/output(I/O)redirectionandpipes.
Implementationsoftheawklanguageareavailableformanydifferentcomputing
environments.Thisbook,whiledescribingtheawklanguageingeneral,alsodescribesthe
particularimplementationofawkcalledgawk(whichstandsfor“GNUawk”).gawkrunson
abroadrangeofUnixsystems,rangingfromIntel-architecturePC-basedcomputersup
throughlarge-scalesystems.gawkhasalsobeenportedtoMacOSX,MicrosoftWindows
(allversions),andOpenVMS.[3]


Historyofawkandgawk
RECIPEFORAPROGRAMMINGLANGUAGE
1partegrep 1partsnobol
2partsed

3partsC

Blendallpartswellusinglexandyacc.Documentminimallyandrelease.
Aftereightyears,addanotherpartegrepandtwomorepartsC.Documentverywellandrelease.

Thenameawkcomesfromtheinitialsofitsdesigners:AlfredV.Aho,PeterJ.Weinberger,
andBrianW.Kernighan.Theoriginalversionofawkwaswrittenin1977atAT&TBell
Laboratories.In1985,anewversionmadetheprogramminglanguagemorepowerful,
introducinguser-definedfunctions,multipleinputstreams,andcomputedregular
expressions.ThisnewversionbecamewidelyavailablewithUnixSystemVRelease3.1

(1987).TheversioninSystemVRelease4(1989)addedsomenewfeaturesandcleaned
upthebehaviorinsomeofthe“darkcorners”ofthelanguage.Thespecificationforawkin
thePOSIXCommandLanguageandUtilitiesstandardfurtherclarifiedthelanguage.Both
thegawkdesignersandtheoriginalawkdesignersatBellLaboratoriesprovidedfeedback
forthePOSIXspecification.
PaulRubinwrotegawkin1986.JayFenlasoncompletedit,withadvicefromRichard
Stallman.JohnWoodscontributedpartsofthecodeaswell.In1988and1989,David
Trueman,withhelpfromme,thoroughlyreworkedgawkforcompatibilitywiththenewer
awk.Circa1994,Ibecametheprimarymaintainer.Currentdevelopmentfocusesonbug
fixes,performanceimprovements,standardscompliance,and,occasionally,newfeatures.
InMay1997,JürgenKahrsfelttheneedfornetworkaccessfromawk,andwithalittle
helpfromme,setaboutaddingfeaturestodothisforgawk.Atthattime,healsowrotethe
bulkofTCP/IPInternetworkingwithgawk(aseparatedocument,availableaspartofthe
gawkdistribution).Hiscodefinallybecamepartofthemaingawkdistributionwithgawk
version3.1.
JohnHaquerewrotethegawkinternals,intheprocessprovidinganawk-leveldebugger.
Thisversionbecameavailableasgawkversion4.0in2011.
SeeMajorContributorstogawkforafulllistofthosewhohavemadeimportant
contributionstogawk.


ARosebyAnyOtherName
Theawklanguagehasevolvedovertheyears.FulldetailsareprovidedinAppendixA.
Thelanguagedescribedinthisbookisoftenreferredtoas“newawk.”Byanalogy,the
originalversionofawkisreferredtoas“oldawk.”
Onmostcurrentsystems,whenyouruntheawkutilityyougetsomeversionofnewawk.[4]
Ifyoursystem’sstandardawkistheoldone,youwillseesomethinglikethisifyoutrythe
testprogram:
$awk1/dev/null
error→awk:syntaxerrornearline1

error→awk:bailingoutnearline1

Inthiscase,youshouldfindaversionofnewawk,orjustinstallgawk!
Throughoutthisbook,wheneverwerefertoalanguagefeaturethatshouldbeavailablein
anycompleteimplementationofPOSIXawk,wesimplyusethetermawk.Whenreferring
toafeaturethatisspecifictotheGNUimplementation,weusethetermgawk.


UsingThisBook
Thetermawkreferstoaparticularprogramaswellastothelanguageyouusetotellthis
programwhattodo.Whenweneedtobecareful,wecallthelanguage“theawk
language,”andtheprogram“theawkutility.”Thisbookexplainsbothhowtowrite
programsintheawklanguageandhowtoruntheawkutility.Theterm“awkprogram”
referstoaprogramwrittenbyyouintheawkprogramminglanguage.
Primarily,thisbookexplainsthefeaturesofawkasdefinedinthePOSIXstandard.Itdoes
sointhecontextofthegawkimplementation.Whiledoingso,italsoattemptstodescribe
importantdifferencesbetweengawkandotherawkimplementations.Finally,itnotesany
gawkfeaturesthatarenotinthePOSIXstandardforawk.
Thisbookhasthedifficulttaskofbeingbothatutorialandareference.Ifyouarea
novice,feelfreetoskipoverdetailsthatseemtoocomplex.Youshouldalsoignorethe
manycross-references;theyarefortheexpertuserandfortheonlineInfoandHTML
versionsofthebook.
Therearesidebarsscatteredthroughoutthebook.Theyaddamorecompleteexplanation
ofpointsthatarerelevant,butnotlikelytobeofinterestonfirstreading.
Mostofthetime,theexamplesusecompleteawkprograms.Someofthemoreadvanced
sectionsshowonlythepartoftheawkprogramthatillustratestheconceptbeingdescribed.
Althoughthisbookisaimedprincipallyatpeoplewhohavenotbeenexposedtoawk,there
isalotofinformationherethateventheawkexpertshouldfinduseful.Inparticular,the
descriptionofPOSIXawkandtheexampleprogramsinChapter10andChapter11should
beofinterest.

Thisbookissplitintoseveralparts,asfollows:
PartI,describestheawklanguageandthegawkprogramindetail.Itstartswiththe
basics,andcontinuesthroughallofthefeaturesofawk.Itcontainsthefollowing
chapters:
Chapter1,GettingStartedwithawk,providestheessentialsyouneedtoknowtobegin
usingawk.
Chapter2,Runningawkandgawk,describeshowtorungawk,themeaningofits
command-lineoptions,andhowitfindsawkprogramsourcefiles.
Chapter3,RegularExpressions,introducesregularexpressionsingeneral,andin
particulartheflavorssupportedbyPOSIXawkandgawk.
Chapter4,ReadingInputFiles,describeshowawkreadsyourdata.Itintroducesthe
conceptsofrecordsandfields,aswellasthegetlinecommand.I/Oredirectionisfirst
describedhere.NetworkI/Oisalsobrieflyintroducedhere.
Chapter5,PrintingOutput,describeshowawkprogramscanproduceoutputwith
printandprintf.
Chapter6,Expressions,describesexpressions,whicharethebasicbuildingblocksfor
gettingmostthingsdoneinaprogram.
Chapter7,Patterns,Actions,andVariables,describeshowtowritepatternsfor
matchingrecords,actionsfordoingsomethingwhenarecordismatched,andthe
predefinedvariablesawkandgawkuse.


Chapter8,Arraysinawk,coversawk’soneandonlydatastructure:theassociative
array.Deletingarrayelementsandwholearraysisdescribed,aswellassortingarrays
ingawk.Thechapteralsodescribeshowgawkprovidesarraysofarrays.
Chapter9,Functions,describesthebuilt-infunctionsawkandgawkprovide,aswellas
howtodefineyourownfunctions.Italsodiscusseshowgawkletsyoucallfunctions
indirectly.
PartII,showshowtouseawkandgawkforproblemsolving.Thereislotsofcodehere
foryoutoreadandlearnfrom.Thispartcontainsthefollowingchapters:

Chapter10,ALibraryofawkFunctions,providesanumberoffunctionsmeanttobe
usedfrommainawkprograms.
Chapter11,PracticalawkPrograms,providesmanysampleawkprograms.
Readingthesetwochaptersallowsyoutoseeawksolvingrealproblems.
PartIII,focusesonfeaturesspecifictogawk.Itcontainsthefollowingchapters:
Chapter12,AdvancedFeaturesofgawk,describesanumberofadvancedfeatures.Of
particularnotearetheabilitiestocontroltheorderofarraytraversal,havetwo-way
communicationswithanotherprocess,performTCP/IPnetworking,andprofileyour
awkprograms.
Chapter13,Internationalizationwithgawk,describesspecialfeaturesfortranslating
programmessagesintodifferentlanguagesatruntime.
Chapter14,DebuggingawkPrograms,describesthegawkdebugger.
Chapter15,ArithmeticandArbitrary-PrecisionArithmeticwithgawk,describes
advancedarithmeticfacilities.
Chapter16,WritingExtensionsforgawk,describeshowtoaddnewvariablesand
functionstogawkbywritingextensionsinCorC++.
PartIV,providesthefollowingappendices,includingtheGNUGeneralPublic
License:
AppendixA,describeshowtheawklanguagehasevolvedsinceitsfirstreleasetothe
present.Italsodescribeshowgawkhasacquiredfeaturesovertime.
AppendixB,describeshowtogetgawk,howtocompileitonPOSIX-compatible
systems,andhowtocompileanduseitondifferentnon-POSIXsystems.Italso
describeshowtoreportbugsingawkandwheretogetotherfreelyavailableawk
implementations.
AppendixC,presentsthelicensethatcoversthegawksourcecode.
Theversionofthisbookdistributedwithgawkcontainsadditionalappendicesandother
endmaterial.Tosavespace,wehaveomittedthemfromtheprintededition.Youmayfind
themonline,asfollows:
Theappendixonimplementationnotesdescribeshowtodisablegawk’sextensions,
howtocontributenewcodetogawk,wheretofindinformationonsomepossiblefuture

directionsforgawkdevelopment,andthedesigndecisionsbehindtheextensionAPI.
Theappendixonbasicconceptsprovidessomeverycursorybackgroundmaterialfor
thosewhoarecompletelyunfamiliarwithcomputerprogramming.


Theglossarydefinesmost,ifnotall,ofthesignificanttermsusedthroughoutthebook.
Ifyoufindtermsthatyouaren’tfamiliarwith,trylookingthemuphere.
TheGNUFDListhelicensethatcoversthisbook.
Someofthechaptershaveexercisesections;thesehavealsobeenomittedfromtheprint
editionbutareavailableonline.


TypographicalConventions
ThisbookiswritteninTexinfo,theGNUdocumentationformattinglanguage.Asingle
Texinfosourcefileisusedtoproduceboththeprintedandonlineversionsofthe
documentation.Becauseofthis,thetypographicalconventionsareslightlydifferentthan
inotherbooksyoumayhaveread.
Examplesyouwouldtypeatthecommandlineareprecededbythecommonshellprimary
andsecondaryprompts,‘$’and‘>’.Inputthatyoutypeisshownlikethis.Outputfrom
thecommand,usuallyitsstandardoutput,appearslikethis.Errormessagesandother
outputonthecommand’sstandarderrorareprecededbytheglyph“error→”.For
example:
$echohionstdout
hionstdout
$echohelloonstderr1>&2
error→helloonstderr

Inthetext,almostanythingrelatedtoprogramming,suchascommandnames,variable
andfunctionnames,andstring,numericandregexpconstantsappearinthisfont.Code
fragmentsappearinthesamefontandquoted,‘likethis’.Thingsthatarereplacedby

theuserorprogrammerappearinthisfont.Optionslooklikethis:-f.Filenamesare
indicatedlikethis:/path/to/ourfile.Thefirstoccurrenceofanewtermisusuallyits
definitionandappearsinthesamefontasthepreviousoccurrenceof“definition”inthis
sentence.
Charactersthatyoutypeatthekeyboardlooklikethis.Inparticular,therearespecial
characterscalled“controlcharacters.”Thesearecharactersthatyoutypebyholdingdown
boththeCONTROLkeyandanotherkey,atthesametime.Forexample,aCtrl-distyped
byfirstpressingandholdingtheCONTROLkey,nextpressingthedkey,andfinally
releasingbothkeys.
Forthesakeofbrevity,throughoutthisbook,werefertoBrianKernighan’sversionofawk
as“BWKawk.”(SeeOtherFreelyAvailableawkImplementationsforinformationonhis
andotherversions.)
NOTE
Notesofinterestlooklikethis.
CAUTION
Cautionaryorwarningnoteslooklikethis.

DarkCorners
Darkcornersarebasicallyfractal—nomatterhowmuchyouilluminate,there’salwaysasmallerbutdarkerone.
—BrianKernighan

UntilthePOSIXstandard(andEffectiveawkProgramming),manyfeaturesofawkwere
eitherpoorlydocumentedornotdocumentedatall.Descriptionsofsuchfeatures(often
called“darkcorners”)arenotedinthisbookwith“(d.c.).”
But,asnotedbytheopeningquote,anycoverageofdarkcornersisbydefinition
incomplete.


Extensionstothestandardawklanguagethataresupportedbymorethanoneawk
implementationaremarked“(c.e.)”for“commonextension.”



TheGNUProjectandThisBook
TheFreeSoftwareFoundation(FSF)isanonprofitorganizationdedicatedtothe
productionanddistributionoffreelydistributablesoftware.ItwasfoundedbyRichardM.
Stallman,theauthoroftheoriginalEmacseditor.GNUEmacsisthemostwidelyused
versionofEmacstoday.
TheGNU[5]ProjectisanongoingeffortonthepartoftheFreeSoftwareFoundationto
createacomplete,freelydistributable,POSIX-compliantcomputingenvironment.The
FSFusestheGNUGeneralPublicLicense(GPL)toensurethatitssoftware’ssourcecode
isalwaysavailabletotheenduser.TheGPLappliestotheClanguagesourcecodefor
gawk.TofindoutmoreabouttheFSFandtheGNUProjectonline,seetheGNUProject’s
homepage.ThisbookmayalsobereadfromGNU’swebsite.
Thebookyouarereadingisactuallyfree—atleast,theinformationinitisfreeto
anyone.Themachine-readablesourcecodeforthebookcomeswithgawk.
Thebookitselfhasgonethroughmultiplepreviouseditions.PaulRubinwrotethevery
firstdraftofTheGAWKManual;itwasaround40pageslong.DianeCloseandRichard
Stallmanimprovedit,yieldingaversionthatwasaround90pagesandbarelydescribed
theoriginal,“old”versionofawk.
Istartedworkingwiththatversioninthefallof1988.Asworkonitprogressed,theFSF
publishedseveralpreliminaryversions(numbered0.x).In1996,edition1.0wasreleased
withgawk3.0.0.TheFSFpublishedthefirsttwoeditionsunderthetitleTheGNUAwk
User’sGuide.SSCpublishedtwoeditionsofthebookunderthetitleEffectiveawk
Programming,andO’Reillypublishedthethirdeditionin2001.
Thiseditionmaintainsthebasicstructureofthepreviouseditions.ForFSFedition4.0,the
contentwasthoroughlyreviewedandupdated.Allreferencestogawkversionspriorto4.0
wereremoved.OfsignificantnoteforthateditionwastheadditionofChapter14.
ForFSFedition4.1(thefourtheditionaspublishedbyO’Reilly),thecontenthasbeen
reorganizedintoparts,andthemajornewadditionsareChapter15andChapter16.
Thisbookwillundoubtedlycontinuetoevolve.Ifyoufindanerrorinthebook,please

reportit!SeeReportingProblemsandBugsforinformationonsubmittingproblemreports
electronically.


HowtoStayCurrent
Youmayhaveanewerversionofgawkthantheonedescribedhere.Tofindoutwhathas
changed,youshouldfirstlookattheNEWSfileinthegawkdistribution,whichprovidesa
high-levelsummaryofthechangesineachrelease.
Youcanthenlookattheonlineversionofthisbooktoreadaboutanynewfeatures.


UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Mostoftheexampleprogramsinthis
bookcomeinthegawkdistributionandaremarkedinthefilesasbeinginthepublic
domain.So,ingeneral,youmayusethecodeinthisbookinyourprogramsand
documentation.Incorporatingasignificantamountofproseorexamplecodefromthis
bookintoyourproduct’sdocumentationrequirescompliancewiththeGNUFDL.
Weappreciate,butdonotrequire,attribution.Anattributionusuallyincludesthetitle,
author,publisher,andISBN.Forexample:“EffectiveawkProgramming,FourthEdition,
byArnoldRobbins(O’Reilly).Copyright2015FreeSoftwareFoundation,978-1-49190461-9.”
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseorthepermissiongivenhere,
feelfreetocontactusat


Safari®BooksOnline
NOTE
SafariBooksOnline(www.safaribooksonline.com)isanon-demanddigitallibrarythatdeliversexpertcontentinboth
bookandvideoformfromtheworld’sleadingauthorsintechnologyandbusiness.

Technologyprofessionals,softwaredevelopers,webdesigners,andbusinessandcreative

professionalsuseSafariBooksOnlineastheirprimaryresourceforresearch,problem
solving,learning,andcertificationtraining.
SafariBooksOnlineoffersarangeofproductmixesandpricingprogramsfor
organizations,governmentagencies,andindividuals.Subscribershaveaccessto
thousandsofbooks,trainingvideos,andprepublicationmanuscriptsinonefully
searchabledatabasefrompublisherslikeO’ReillyMedia,PrenticeHallProfessional,
Addison-WesleyProfessional,MicrosoftPress,Sams,Que,PeachpitPress,FocalPress,
CiscoPress,JohnWiley&Sons,Syngress,MorganKaufmann,IBMRedbooks,Packt,
AdobePress,FTPress,Apress,Manning,NewRiders,McGraw-Hill,Jones&Bartlett,
CourseTechnology,anddozensmore.FormoreinformationaboutSafariBooksOnline,
pleasevisitusonline.


HowtoContactUs
Pleaseaddresscommentsandquestionsconcerningthisbooktothepublisher:
O’ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
800-998-9938(intheUnitedStatesorCanada)
707-829-0515(internationalorlocal)
707-829-0104(fax)

Wehaveawebpageforthisbook,wherewelisterrata,examples,andanyadditional
information.Youcanaccessthispageat />Tocommentorasktechnicalquestionsaboutthisbook,sendemailto

Formoreinformationaboutourbooks,courses,conferences,andnews,seeourwebsiteat
.
FindusonFacebook: />FollowusonTwitter: />WatchusonYouTube: />

Acknowledgments

TheinitialdraftofTheGAWKManualhadthefollowingacknowledgments:
Manypeopleneedtobethankedfortheirassistanceinproducingthismanual.JayFenlasoncontributedmanyideas
andsampleprograms.RichardMlynarikandRobertChassellgavehelpfulcommentsondraftsofthismanual.The
paperASupplementalDocumentforawkbyJohnW.PierceoftheChemistryDepartmentatUCSanDiego,
pinpointedseveralissuesrelevantbothtoawkimplementationandtothismanual,thatwouldotherwisehave
escapedus.

IwouldliketoacknowledgeRichardM.Stallman,forhisvisionofabetterworldandfor
hiscourageinfoundingtheFSFandstartingtheGNUProject.
Thepreviouseditionofthisbookhadthefollowingacknowledgments:
Thefollowingpeople(inalphabeticalorder)providedhelpfulcommentsonvariousversionsofthisbook:Rick
Adams,Dr.NelsonH.F.Beebe,KarlBerry,Dr.MichaelBrennan,RichBurridge,ClaireCloutier,DianeClose,
ScottDeifik,Christopher(“Topher”)Eliot,JeffreyFriedl,Dr.DarrelHankerson,MichalJaegermann,Dr.RichardJ.
LeBlanc,MichaelLijewski,PatRankin,MiriamRobbins,MarySheehan,andChuckToporek.
RobertJ.ChassellprovidedmuchvaluableadviceontheuseofTexinfo.Healsodeservesspecialthanksfor
convincingmenottotitlethisbookHowtoGawkPolitely.KarlBerryhelpedsignificantlywiththeTeXpartof
Texinfo.
IwouldliketothankMarshallandElaineHartholzofSeattleandDr.BertandRitaSchreiberofDetroitforlarge
amountsofquietvacationtimeintheirhomes,whichallowedmetomakesignificantprogressonthisbookandon
gawkitself.
PhilHughesofSSCcontributedinaveryimportantwaybyloaningmehislaptopGNU/Linuxsystem,notonce,
buttwice,whichallowedmetodoalotofworkwhileawayfromhome.
DavidTruemandeservesspecialcredit;hehasdoneayeomanjobofevolvinggawksothatitperformswelland
withoutbugs.Althoughheisnolongerinvolvedwithgawk,workingwithhimonthisprojectwasasignificant
pleasure.
TheintrepidmembersoftheGNITSmailinglist,andmostnotablyUlrichDrepper,providedinvaluablehelpand
feedbackforthedesignoftheinternationalizationfeatures.
ChuckToporek,MarySheehan,andClaireCloutierofO’Reilly&Associatescontributedsignificanteditorialhelp
forthisbookforthe3.1releaseofgawk.


Dr.NelsonBeebe,AndreasBuening,Dr.ManuelCollado,AntonioColombo,Stephen
Davies,ScottDeifik,AkimDemaille,DarrelHankerson,MichalJaegermann,Jürgen
Kahrs,StepanKasal,JohnMalmberg,DavePitts,ChetRamey,PatRankin,Andrew
Schorr,CorinnaVinschen,andEliZaretskii(inalphabeticalorder)makeupthecurrent
gawk“crackportabilityteam.”Withouttheirhardworkandhelp,gawkwouldnotbenearly
therobust,portableprogramitistoday.Ithasbeenandcontinuestobeapleasureworking
withthisteamoffinepeople.
Notablecodeanddocumentationcontributionsweremadebyanumberofpeople.See
MajorContributorstogawkforthefulllist.
ThankstoAndyOramofO’ReillyMediaforinitiatingthefourtheditionandforhis
supportduringthework.ThankstoJasmineKwitynforhercopyeditingwork.
ThankstoMichaelBrennanfortheForewords.
ThankstoPatriceDumasforthenewmakeinfoprogram.ThankstoKarlBerry,who
continuestoworktokeeptheTexinfomarkuplanguagesane.
RobertP.J.Day,MichaelBrennan,andBrianKernighankindlyactedasreviewersforthe


2015editionofthisbook.Theirfeedbackhelpedimprovethefinalwork.
IwouldalsoliketothankBrianKernighanforhisinvaluableassistanceduringthetesting
anddebuggingofgawk,andforhisongoinghelpandadviceinclarifyingnumerouspoints
aboutthelanguage.Wecouldnothavedonenearlyasgoodajoboneithergawkorits
documentationwithouthishelp.
Brianisinaclassbyhimselfasaprogrammerandtechnicalauthor.Ihavetothankhim
(yetagain)forhisongoingfriendshipandforbeingarolemodeltomeforcloseto30
years!Havinghimasareviewerisanexcitingprivilege.Ithasalsobeenextremely
humbling…
Imustthankmywonderfulwife,Miriam,forherpatiencethroughthemanyversionsof
thisproject,forherproofreading,andforsharingmewiththecomputer.Iwouldliketo
thankmyparentsfortheirlove,andforthegracewithwhichtheyraisedandeducatedme.
Finally,IalsomustacknowledgemygratitudetoG-d,forthemanyopportunitiesHehas

sentmyway,aswellasforthegiftsHehasgivenmewithwhichtotakeadvantageof
thoseopportunities.
[1]The2008POSIXstandardisaccessibleonline.
[2]TheseutilitiesareavailableonPOSIX-compliantsystems,aswellasontraditionalUnix-basedsystems.Ifyouare
usingsomeotheroperatingsystem,youstillneedtobefamiliarwiththeideasofI/Oredirectionandpipes.
[3]Someother,obsoletesystemstowhichgawkwasonceportedarenolongersupportedandthecodeforthosesystems
hasbeenremoved.
[4]OnlySolarissystemsstilluseanoldawkforthedefaultawkutility.Amoremodernawklivesin/usr/xpg6/binon
thesesystems.
[5]GNUstandsfor“GNU’sNotUnix.”


×