= Overview of awk = == The primarily purpose of awk is to processing textual data to produce formatted reports == The [[awk]] extraction and reporting language is [[data driven]] and is primarily used for taking [[action]]s against textual data for the purpose of producing formatted reports. == Components of an awk program == A [[script]] in [[awk]] may contain the following components: * [[comment]]s * [[rule]]s * [[function]] definitions * [[hashbang]] == The awk utility performs a cycle of pattern matching and performing associated actions == The [[awk]] utility takes each [[line]] of [[input]] and compares with each [[pattern]] in the [[script]]. If a [[pattern]] matches the [[input line]], [[awk]] takes the [[action]] associated with the [[pattern]]. If the line does not match the [[pattern]], the [[awk]] utility takes no action. If more than one [[pattern]] matches the [[input file]], then the [[action]] associated with each [[pattern]] are carried out in the order in which they are defined in the [[awk]] script. When [[awk]] has completed its comparisons for the first line of the [[input file]], the cycle is repeated for each of the subsequent lines in of [[input]], until all lines have been read. == The awk utility can perform mathematical operations == The awk utility can perform mathematical operations. This makes [[awk]] a useful tool for producing tallies and summaries: == It is possible to process multiple files using patterns and actions == Using [[awk]], it is possible to search one or more files for specified [[pattern]] matches and performing associated [[action]]s. == The awk language supports common programming constructs == The [[awk]] language provides support for programming constructs such as [[loop]]s and conditional [[branch]]es, and enables [[arithmetic]] and [[string]] operations to be performed. == Where is awk on the hammer scale? == The [[awk]] utility is rated at 3 (a General Hammer) on the [[http://markhobley.yi.org/programming/hammers/index.html|hammer scale]], and is classified as "A general purpose package with various configuration options, some of which may not be needed." == Syntax == Each line of an [[awk]] script has the following [[syntax]]: pattern { action } The [[pattern]] is used to select lines from the [[input file]]. The [[awk]] utility performs the associated [[action]] on all lines that are selected by the [[pattern]]. The [[action]] is enclosed within [[brace]]s so that the [[awk]] interpreter can differentiate it from the pattern. If several [[pattern]]s select the same line, [[awk]] takes the actions associated with each of the [[pattern]]s in the order that they first appear within the [[program]]. It is possible for [[awk]] to send a single line from the [[input file]] to its [[standard output]] more than once. == Notes == If a [[program line]] does not contain a [[pattern]], the [[awk]] utility applies the [[action]] to all lines in the [[input file]]. If a [[program line]] does not contain an [[action]], [[awk]] copies the selected lines to [[standard output]].
Summary:
This change is a minor edit.
Username: