{"id":357,"date":"2018-07-13T10:39:18","date_gmt":"2018-07-13T10:39:18","guid":{"rendered":"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=357"},"modified":"2019-05-16T08:58:21","modified_gmt":"2019-05-16T08:58:21","slug":"awk-scripting","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/chapter\/awk-scripting\/","title":{"rendered":"AWK Scripting"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/M4wqmgMi_0A\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n&nbsp;\r\n\r\n<strong>Overview of AWK<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK is a scripting language supported by most of the Linux distributions. AWK supports text processing and is useful in report generation. It is generally used for data extraction from flat files. AWK usually works on streams of textual data to perform set of actions for data extraction. AWK is widely used to generate reports from flat files or from log files. Let us understand the applicability of AWK in networking domain. Suppose, we are using NS2 simulator that simulates large network. This simulator will generate trace files which contain the records of each packet transfer happening in the network. The amount of records generated by NS2 can be in thousands, when we want to generate a summary of the packet transfers, AWK can be used to extract certain records according to user\u201fs criteria. AWK is a widely used tool for reporting purpose.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK was created in 1977 at Bell Labs. The name, AWK is derived from the beginning letters of the surnames of its developers\/authors who were Alfred Aho, Peter Weinberger and Brian Kernighan. Later, during 1985-88, AWK was revised by Paul Rubin, Jay Fenalson and Richard Stallman. The revised AWK version was released in 1988 as GNU AWK. As of now, AWK is available in various Linux distributions, AWK has many variants like gawk, mawk, nawk etc.<\/p>\r\n&nbsp;\r\n\r\n<strong>File Structure and AWK<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK reads from a file or from the standard input. The output of AWK is to its standard output. AWK adheres to the concepts of \"file\", \"record\" and \"field\" as used in flat file model. A structured text file consists of records, usually, each line of a file represent a single record. So, each line is a record for AWK. AWK operates on one record at a time. A record consists of field(s) which are structured as columns, these fields are separated by space(s) or tab(s) by default. Each filed can be accessed by prefixing \u201e$\u201f sign, so the first field can be accessed as $1, field 2 with $2, and so on, however, the field $0 refers to the whole record. Hence a structure file containing rows are identified as records and columns are identified as fields. The following figure is an example of flat file structure where rows are identified as different records and columns are identified as fields:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-358 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X26.jpg\" alt=\"\" width=\"540\" height=\"270\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 1: Flat File Model(Source: https:\/\/commons.wikimedia.org\/wiki\/File:Flat_File_Model.svg)<\/p>\r\n&nbsp;\r\n\r\nLet us take an example to understand the structure of file. Suppose a system with \/etc\/passwd file contains the following entries in its tail section:\r\n\r\n&nbsp;\r\n\r\n<strong>hardik:x:504:504::\/home\/hardik:\/bin\/bash hiren:x:505:505::\/home\/hiren:\/bin\/bash rakesh:x:506:506::\/home\/rakesh:\/bin\/bash<\/strong>\r\n\r\n&nbsp;\r\n\r\nAWK will see this file as follows:\r\n<p style=\"text-align: justify;\">1 line indicates 1 record, so in total there are 3 records in the above mentioned file. 1 record indicates 7 fields in the above case, the records are separated by \u201c:\u201d. It must be noted that by default, the field separator is space.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK is a programming language. AWK uses specific structure of program to perform pattern matching. An awk program is a sequence of statements that take the following form:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-359 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X18.png\" alt=\"\" width=\"211\" height=\"164\" \/><\/p>\r\n&nbsp;\r\n\r\nIn general, the format is as follows:\r\n\r\n&nbsp;\r\n\r\n<strong>awk options \u201eselection criteria {actions}\u201f file(s)<\/strong>\r\n<p style=\"text-align: justify;\">Where, pattern acts as a selector that determines whether the action is to be executed. Patterns can be: arithmetic expressions, relational expressions, regular expressions string-valued or boolean expressions. These actions can be a\u00a0sequence of statements terminated by newlines or semicolons. AWK programs can either be executed on command prompt or written in a file. The following figure illustrates use of pattern matching in AWK:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-360 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X27.jpg\" alt=\"\" width=\"660\" height=\"336\" \/><\/p>\r\n<p style=\"text-align: center;\"><strong>Figure 2: AWK patterns and field<\/strong><\/p>\r\n&nbsp;\r\n\r\nNow, let us see how AWK can be used to fetch various patterns from the file.\r\n\r\nAWK Command to fetch the userid of user \u201chardik\u201d:\r\n\r\n<strong>$awk -F\":\" \u201e\/hardik\/ {print $1 \" \" $3}\u201f \/etc\/passwd<\/strong>\r\n\r\nOutput:\r\n\r\nhardik 504\r\n\r\nAnother way to write the command is:\r\n\r\n<strong>$awk \u201eBEGIN { FS=\u201c:\u201d } \/hardik\/ {print $1 \" \" $3}\u201f \/etc\/passwd<\/strong>\r\n\r\nOutput:\r\n\r\nhardik 504\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the above example, print command is used to output text on standard output. The output text is always terminated with a newline. Here, the \u201eF\u201f option is used to specify field separator which is \u201e:\u201f. The print command can be used as follows to display the first field:<\/p>\r\n&nbsp;\r\n\r\n<strong>print $1<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following command displays the first field and third field of the current record:\r\n\r\n<strong>print $1, $3<\/strong>\r\n<p style=\"text-align: justify;\">Let us see other few examples to understand the use of AWK. In the following example, we will consider a student record file. The content of file \u201estmarks.dat\u201f are student no, name, marks in subject-1, marks in subject-2 and marks in subject-3. Each record is a line in the file, a space separates each field. The content of file as shown below:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-361 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X28.jpg\" alt=\"\" width=\"662\" height=\"221\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 3: Content of stmarks.dat file<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">To display the initial two fields of file \u201estmarks.dat\u201f, we use the print command as shown earlier. However, here the field separator is space so there is no need to explicitly specify the field separator using the \u201eF\u201f option. The following figure demonstrates use of print command with awk:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-362 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X29.jpg\" alt=\"\" width=\"662\" height=\"240\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 4: Using print command with awk<\/p>\r\n&nbsp;\r\n\r\n<strong>Using operators with AWK<\/strong>\r\n<p style=\"text-align: left;\">AWK supports a wide range of operators. The following table lists various comparison operators supported\u00a0 by AWX:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-363 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X78.png\" alt=\"\" width=\"566\" height=\"376\" \/>.<\/p>\r\nThe following screen-shot demonstrates an example where comparision operator is applied. In the following screen, the command lists the student number and student name who have scored marks above 60 in subject-1:\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-364 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1.png\" alt=\"\" width=\"566\" height=\"376\" \/><\/p>\r\nThe following screen-shot demonstrates an example where comparision operator is applied. In the following screen, the command lists the student number and student name who have scored marks above 60 in subject-1:\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-365 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1.jpg\" alt=\"\" width=\"517\" height=\"207\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 5: Using comparison operator in awk <strong>Using Arithmetic Operators with AWK<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK supports arithmetic operators like addition (+), subtraction (-), multiplication (*), division (\/), remainder (%), exponentiation (^), increment (++) and decrement (--) with pattern matching.The following illustration demonstrates the use of addition operator to display those records where the total of marks of three subjects is above 180:<\/p>\r\n<img class=\"alignnone size-full wp-image-366 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X30.jpg\" alt=\"\" width=\"662\" height=\"202\" \/>\r\n<p style=\"text-align: center;\">Figure 6: Using arithmetic operators with AWK<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\">In the following figure, we have applied multiple conditions to selectively filter records. The following example demonstrates the display of only those records where the marks in 3 different subjects are above 50:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-367 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X31.jpg\" alt=\"\" width=\"798\" height=\"154\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 7: Comparison and &amp;&amp; operator with AWK<\/p>\r\n&nbsp;\r\n\r\n<strong>Using regular expression with AWK<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us see an example how regular expression can be used with AWK. In the following illustration, we are listing those records where the student name begin with \u201eR\u201f:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-368 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X32.jpg\" alt=\"\" width=\"798\" height=\"280\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 8: Using regular expression with AWK<\/p>\r\n&nbsp;\r\n<p style=\"text-align: left;\"><strong>Using Built-in variables with AWK<\/strong><\/p>\r\n<p style=\"text-align: justify;\">AWK supports the use of both user-defined variables and built-in variables. In this section, let us explore the built-in variables supported by AWK. The built-in variables are used in AWK script<\/p>\r\n&nbsp;\r\n\r\nThe following variables are supported by AWK:\r\n<ul>\r\n \t<li><strong>NR: <\/strong>Keeps count of the number of input records, indicates current record.<\/li>\r\n \t<li><strong>NF: <\/strong>Keeps a count of the number of fields<\/li>\r\n \t<li><strong>FILENAME: <\/strong>The name of the current input-file<\/li>\r\n \t<li><strong>FNR: <\/strong>No of records in current filename<\/li>\r\n \t<li><strong>FS: <\/strong>Contains the \u201cfield separator\u201d character<\/li>\r\n \t<li><strong>RS: <\/strong>Stores the current \u201crecord separator\u201d or row Separator<\/li>\r\n \t<li><strong>OFS: <\/strong>Stores the \u201coutput field separator\u201d<\/li>\r\n \t<li><strong>ORS: <\/strong>Stores the \u201coutput record separator\u201d<\/li>\r\n \t<li style=\"text-align: justify;\">Built-in variables also include the field variables like $1, $2, $3, and so on (where $0 represents the entire record). These variables contain the values\/text stored in the individual text-fields in a record.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\">let us study how built-in variables can be used while processing records. In the following example, we are displaying the record count which is indicated as line number before the record:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-369 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X33.jpg\" alt=\"\" width=\"662\" height=\"234\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 8: Using built-in variables with AWK<\/p>\r\n&nbsp;\r\n\r\n<strong>Creating AWK Scripts<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK scripts are small programs that can perform multiple actions combined. Usually, the awk scripts are saved with .awk file extension. AWK script provides the facility of pre-processing and post-processing using the BEGIN and END keywords. For instance, if we want to print something before the input process starts, the BEGIN section can be used. Similarly, the END section is useful to print something after the processing gets over. BEGIN and END sections are optional. The structure of AWK script is as follows:<\/p>\r\n\r\n<ul>\r\n \t<li>An optional <strong>BEGIN<\/strong> Statement (used for processing that executes prior to reading input)<\/li>\r\n \t<li>Pattern \u2013 action pairs(used for processing input data &amp; matching patterns if any)<\/li>\r\n \t<li>An optional <strong>END<\/strong> segment(used for processing after end of input data)<\/li>\r\n<\/ul>\r\nLet us see an example of AWK script to calculate the total marks of subject-3 for all students using the stmarks.dat file.\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-370 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X35.png\" alt=\"\" width=\"640\" height=\"185\" \/><\/p>\r\n<p style=\"text-align: justify;\">In the given script, we process stmarks.dat file that was discussed earlier. The script is stored in sample.awk file. BEGIN section is used to initialize a user-defined \u201esum\u201f variable while the END section is used to display the content of sum variable.<\/p>\r\n&nbsp;\r\n\r\nBEGIN can be used to print headers as follows:\r\n\r\n&nbsp;\r\n\r\n<strong>$awk \u201eBEGIN{printf \u201cNo\\tName\\tSub \\tMarks\\n\u201d} {print}\u201f stmarks.dat <\/strong><strong>Few other features of AWK<\/strong>\r\n<p style=\"text-align: justify;\">AWK supports usage of functions like length(), substr(), index(), split() etc to perform operations on strings. These functions can be used to perform string operations. Mathematical functions like sqrt(), etc. are also supported. AWK also supports if statement that is used for control flow. Looping structures like for and while are also supported by AWK. Looping can be used frequently when we want to process an array or string.<\/p>\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us summarize what we have studied in this module:<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">AWK is a programming language that has BEGIN-END format while scripting AWK can also be used at command-prompt AWK can process large volume of text-data and can be used for summarizing or reporting purposes<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on AWK Scripting<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/M4wqmgMi_0A\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<strong>References:<\/strong>\r\n<ol>\r\n \t<li style=\"text-align: justify;\">Jacek. Artymiak. 1999. <em>Sams teach yourself Sed and Awk in 24<\/em> <em>hours.<\/em>, Sams.<\/li>\r\n \t<li style=\"text-align: justify;\">Dale. Dougherty and Arnold. Robbins. 1997. <em>Sed &amp; awk<\/em>, O\u2019Reilly.<\/li>\r\n \t<li style=\"text-align: justify;\">Gigi Estabrook, Arnold D. Robbins, and Dale Dougherty. 1997. <em>Sed<\/em> <em>and Awk.<\/em>, O\u2019Reilly Media, Inc.<\/li>\r\n \t<li style=\"text-align: justify;\">Harvey. Foreman and Robert L. (Robert Louis) Jefferson. 1970. <em>Awk!<\/em>, Westminster Press.<\/li>\r\n \t<li style=\"text-align: justify;\">Peter. Patsis. 1999. <em>Unix awk and sed programmer\u2019s interactive<\/em> <em>workbook<\/em>, Prentice Hall PTR.<\/li>\r\n \t<li style=\"text-align: justify;\">Arnold Robbins. <em>Effective AWK programming\u202f: universal text<\/em> <em>processing and pattern matching<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Arnold Robbins. 1997. <em>GAWK\u202f: the GNU awk user\u2019s guide<\/em>, Free Software Foundation.<\/li>\r\n \t<li style=\"text-align: justify;\">Arnold. Robbins. 2002. <em>Sed &amp;amp; awk\u202f: pocket reference<\/em>, O\u2019Reilly.<\/li>\r\n \t<li style=\"text-align: justify;\">Theodore. Romoser and Michael R. Rose. 1972. <em>Awk.: a guide to<\/em> <em>effective writing<\/em>, Canfield Press.<\/li>\r\n<\/ol>\r\n<strong>Online Tutorials:<\/strong>\r\n<ol>\r\n \t<li>https:\/\/<em>www<\/em>.cse.iitb.ac.in\/~br\/courses\/cs699-autumn2013\/refs\/awk-tutorial.html<\/li>\r\n \t<li>http:\/\/www.theunixschool.com\/p\/awk-sed.html<\/li>\r\n<\/ol>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/M4wqmgMi_0A\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Overview of AWK<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK is a scripting language supported by most of the Linux distributions. AWK supports text processing and is useful in report generation. It is generally used for data extraction from flat files. AWK usually works on streams of textual data to perform set of actions for data extraction. AWK is widely used to generate reports from flat files or from log files. Let us understand the applicability of AWK in networking domain. Suppose, we are using NS2 simulator that simulates large network. This simulator will generate trace files which contain the records of each packet transfer happening in the network. The amount of records generated by NS2 can be in thousands, when we want to generate a summary of the packet transfers, AWK can be used to extract certain records according to user\u201fs criteria. AWK is a widely used tool for reporting purpose.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK was created in 1977 at Bell Labs. The name, AWK is derived from the beginning letters of the surnames of its developers\/authors who were Alfred Aho, Peter Weinberger and Brian Kernighan. Later, during 1985-88, AWK was revised by Paul Rubin, Jay Fenalson and Richard Stallman. The revised AWK version was released in 1988 as GNU AWK. As of now, AWK is available in various Linux distributions, AWK has many variants like gawk, mawk, nawk etc.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>File Structure and AWK<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK reads from a file or from the standard input. The output of AWK is to its standard output. AWK adheres to the concepts of &#8220;file&#8221;, &#8220;record&#8221; and &#8220;field&#8221; as used in flat file model. A structured text file consists of records, usually, each line of a file represent a single record. So, each line is a record for AWK. AWK operates on one record at a time. A record consists of field(s) which are structured as columns, these fields are separated by space(s) or tab(s) by default. Each filed can be accessed by prefixing \u201e$\u201f sign, so the first field can be accessed as $1, field 2 with $2, and so on, however, the field $0 refers to the whole record. Hence a structure file containing rows are identified as records and columns are identified as fields. The following figure is an example of flat file structure where rows are identified as different records and columns are identified as fields:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-358 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X26.jpg\" alt=\"\" width=\"540\" height=\"270\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X26.jpg 540w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X26-300x150.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X26-65x33.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X26-225x113.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X26-350x175.jpg 350w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 1: Flat File Model(Source: https:\/\/commons.wikimedia.org\/wiki\/File:Flat_File_Model.svg)<\/p>\n<p>&nbsp;<\/p>\n<p>Let us take an example to understand the structure of file. Suppose a system with \/etc\/passwd file contains the following entries in its tail section:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>hardik:x:504:504::\/home\/hardik:\/bin\/bash hiren:x:505:505::\/home\/hiren:\/bin\/bash rakesh:x:506:506::\/home\/rakesh:\/bin\/bash<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>AWK will see this file as follows:<\/p>\n<p style=\"text-align: justify;\">1 line indicates 1 record, so in total there are 3 records in the above mentioned file. 1 record indicates 7 fields in the above case, the records are separated by \u201c:\u201d. It must be noted that by default, the field separator is space.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK is a programming language. AWK uses specific structure of program to perform pattern matching. An awk program is a sequence of statements that take the following form:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-359 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X18.png\" alt=\"\" width=\"211\" height=\"164\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X18.png 211w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X18-65x51.png 65w\" sizes=\"auto, (max-width: 211px) 100vw, 211px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In general, the format is as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>awk options \u201eselection criteria {actions}\u201f file(s)<\/strong><\/p>\n<p style=\"text-align: justify;\">Where, pattern acts as a selector that determines whether the action is to be executed. Patterns can be: arithmetic expressions, relational expressions, regular expressions string-valued or boolean expressions. These actions can be a\u00a0sequence of statements terminated by newlines or semicolons. AWK programs can either be executed on command prompt or written in a file. The following figure illustrates use of pattern matching in AWK:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-360 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X27.jpg\" alt=\"\" width=\"660\" height=\"336\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X27.jpg 660w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X27-300x153.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X27-65x33.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X27-225x115.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X27-350x178.jpg 350w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/p>\n<p style=\"text-align: center;\"><strong>Figure 2: AWK patterns and field<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Now, let us see how AWK can be used to fetch various patterns from the file.<\/p>\n<p>AWK Command to fetch the userid of user \u201chardik\u201d:<\/p>\n<p><strong>$awk -F&#8221;:&#8221; \u201e\/hardik\/ {print $1 &#8221; &#8221; $3}\u201f \/etc\/passwd<\/strong><\/p>\n<p>Output:<\/p>\n<p>hardik 504<\/p>\n<p>Another way to write the command is:<\/p>\n<p><strong>$awk \u201eBEGIN { FS=\u201c:\u201d } \/hardik\/ {print $1 &#8221; &#8221; $3}\u201f \/etc\/passwd<\/strong><\/p>\n<p>Output:<\/p>\n<p>hardik 504<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the above example, print command is used to output text on standard output. The output text is always terminated with a newline. Here, the \u201eF\u201f option is used to specify field separator which is \u201e:\u201f. The print command can be used as follows to display the first field:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>print $1<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following command displays the first field and third field of the current record:<\/p>\n<p><strong>print $1, $3<\/strong><\/p>\n<p style=\"text-align: justify;\">Let us see other few examples to understand the use of AWK. In the following example, we will consider a student record file. The content of file \u201estmarks.dat\u201f are student no, name, marks in subject-1, marks in subject-2 and marks in subject-3. Each record is a line in the file, a space separates each field. The content of file as shown below:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-361 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X28.jpg\" alt=\"\" width=\"662\" height=\"221\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X28.jpg 662w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X28-300x100.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X28-65x22.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X28-225x75.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X28-350x117.jpg 350w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 3: Content of stmarks.dat file<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">To display the initial two fields of file \u201estmarks.dat\u201f, we use the print command as shown earlier. However, here the field separator is space so there is no need to explicitly specify the field separator using the \u201eF\u201f option. The following figure demonstrates use of print command with awk:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-362 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X29.jpg\" alt=\"\" width=\"662\" height=\"240\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29.jpg 662w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-300x109.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-65x24.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-225x82.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-350x127.jpg 350w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 4: Using print command with awk<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Using operators with AWK<\/strong><\/p>\n<p style=\"text-align: left;\">AWK supports a wide range of operators. The following table lists various comparison operators supported\u00a0 by AWX:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-363 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X78.png\" alt=\"\" width=\"566\" height=\"376\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78.png 566w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-300x199.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-65x43.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-225x149.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-350x233.png 350w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/>.<\/p>\n<p>The following screen-shot demonstrates an example where comparision operator is applied. In the following screen, the command lists the student number and student name who have scored marks above 60 in subject-1:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-364 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1.png\" alt=\"\" width=\"566\" height=\"376\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1.png 566w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1-300x199.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1-65x43.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1-225x149.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X78-1-350x233.png 350w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/p>\n<p>The following screen-shot demonstrates an example where comparision operator is applied. In the following screen, the command lists the student number and student name who have scored marks above 60 in subject-1:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-365 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1.jpg\" alt=\"\" width=\"517\" height=\"207\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1.jpg 517w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1-300x120.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1-65x26.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1-225x90.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X29-1-350x140.jpg 350w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 5: Using comparison operator in awk <strong>Using Arithmetic Operators with AWK<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK supports arithmetic operators like addition (+), subtraction (-), multiplication (*), division (\/), remainder (%), exponentiation (^), increment (++) and decrement (&#8211;) with pattern matching.The following illustration demonstrates the use of addition operator to display those records where the total of marks of three subjects is above 180:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-366 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X30.jpg\" alt=\"\" width=\"662\" height=\"202\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X30.jpg 662w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X30-300x92.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X30-65x20.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X30-225x69.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X30-350x107.jpg 350w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 6: Using arithmetic operators with AWK<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\">In the following figure, we have applied multiple conditions to selectively filter records. The following example demonstrates the display of only those records where the marks in 3 different subjects are above 50:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-367 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X31.jpg\" alt=\"\" width=\"798\" height=\"154\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X31.jpg 798w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X31-300x58.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X31-768x148.jpg 768w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X31-65x13.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X31-225x43.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X31-350x68.jpg 350w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 7: Comparison and &amp;&amp; operator with AWK<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Using regular expression with AWK<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us see an example how regular expression can be used with AWK. In the following illustration, we are listing those records where the student name begin with \u201eR\u201f:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-368 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X32.jpg\" alt=\"\" width=\"798\" height=\"280\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X32.jpg 798w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X32-300x105.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X32-768x269.jpg 768w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X32-65x23.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X32-225x79.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X32-350x123.jpg 350w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 8: Using regular expression with AWK<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left;\"><strong>Using Built-in variables with AWK<\/strong><\/p>\n<p style=\"text-align: justify;\">AWK supports the use of both user-defined variables and built-in variables. In this section, let us explore the built-in variables supported by AWK. The built-in variables are used in AWK script<\/p>\n<p>&nbsp;<\/p>\n<p>The following variables are supported by AWK:<\/p>\n<ul>\n<li><strong>NR: <\/strong>Keeps count of the number of input records, indicates current record.<\/li>\n<li><strong>NF: <\/strong>Keeps a count of the number of fields<\/li>\n<li><strong>FILENAME: <\/strong>The name of the current input-file<\/li>\n<li><strong>FNR: <\/strong>No of records in current filename<\/li>\n<li><strong>FS: <\/strong>Contains the \u201cfield separator\u201d character<\/li>\n<li><strong>RS: <\/strong>Stores the current \u201crecord separator\u201d or row Separator<\/li>\n<li><strong>OFS: <\/strong>Stores the \u201coutput field separator\u201d<\/li>\n<li><strong>ORS: <\/strong>Stores the \u201coutput record separator\u201d<\/li>\n<li style=\"text-align: justify;\">Built-in variables also include the field variables like $1, $2, $3, and so on (where $0 represents the entire record). These variables contain the values\/text stored in the individual text-fields in a record.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">let us study how built-in variables can be used while processing records. In the following example, we are displaying the record count which is indicated as line number before the record:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-369 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X33.jpg\" alt=\"\" width=\"662\" height=\"234\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X33.jpg 662w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X33-300x106.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X33-65x23.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X33-225x80.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X33-350x124.jpg 350w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 8: Using built-in variables with AWK<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Creating AWK Scripts<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK scripts are small programs that can perform multiple actions combined. Usually, the awk scripts are saved with .awk file extension. AWK script provides the facility of pre-processing and post-processing using the BEGIN and END keywords. For instance, if we want to print something before the input process starts, the BEGIN section can be used. Similarly, the END section is useful to print something after the processing gets over. BEGIN and END sections are optional. The structure of AWK script is as follows:<\/p>\n<ul>\n<li>An optional <strong>BEGIN<\/strong> Statement (used for processing that executes prior to reading input)<\/li>\n<li>Pattern \u2013 action pairs(used for processing input data &amp; matching patterns if any)<\/li>\n<li>An optional <strong>END<\/strong> segment(used for processing after end of input data)<\/li>\n<\/ul>\n<p>Let us see an example of AWK script to calculate the total marks of subject-3 for all students using the stmarks.dat file.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-370 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/X35.png\" alt=\"\" width=\"640\" height=\"185\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X35.png 640w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X35-300x87.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X35-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X35-225x65.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/X35-350x101.png 350w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p style=\"text-align: justify;\">In the given script, we process stmarks.dat file that was discussed earlier. The script is stored in sample.awk file. BEGIN section is used to initialize a user-defined \u201esum\u201f variable while the END section is used to display the content of sum variable.<\/p>\n<p>&nbsp;<\/p>\n<p>BEGIN can be used to print headers as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>$awk \u201eBEGIN{printf \u201cNo\\tName\\tSub \\tMarks\\n\u201d} {print}\u201f stmarks.dat <\/strong><strong>Few other features of AWK<\/strong><\/p>\n<p style=\"text-align: justify;\">AWK supports usage of functions like length(), substr(), index(), split() etc to perform operations on strings. These functions can be used to perform string operations. Mathematical functions like sqrt(), etc. are also supported. AWK also supports if statement that is used for control flow. Looping structures like for and while are also supported by AWK. Looping can be used frequently when we want to process an array or string.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us summarize what we have studied in this module:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">AWK is a programming language that has BEGIN-END format while scripting AWK can also be used at command-prompt AWK can process large volume of text-data and can be used for summarizing or reporting purposes<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on AWK Scripting<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/M4wqmgMi_0A\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>References:<\/strong><\/p>\n<ol>\n<li style=\"text-align: justify;\">Jacek. Artymiak. 1999. <em>Sams teach yourself Sed and Awk in 24<\/em> <em>hours.<\/em>, Sams.<\/li>\n<li style=\"text-align: justify;\">Dale. Dougherty and Arnold. Robbins. 1997. <em>Sed &amp; awk<\/em>, O\u2019Reilly.<\/li>\n<li style=\"text-align: justify;\">Gigi Estabrook, Arnold D. Robbins, and Dale Dougherty. 1997. <em>Sed<\/em> <em>and Awk.<\/em>, O\u2019Reilly Media, Inc.<\/li>\n<li style=\"text-align: justify;\">Harvey. Foreman and Robert L. (Robert Louis) Jefferson. 1970. <em>Awk!<\/em>, Westminster Press.<\/li>\n<li style=\"text-align: justify;\">Peter. Patsis. 1999. <em>Unix awk and sed programmer\u2019s interactive<\/em> <em>workbook<\/em>, Prentice Hall PTR.<\/li>\n<li style=\"text-align: justify;\">Arnold Robbins. <em>Effective AWK programming\u202f: universal text<\/em> <em>processing and pattern matching<\/em>,<\/li>\n<li style=\"text-align: justify;\">Arnold Robbins. 1997. <em>GAWK\u202f: the GNU awk user\u2019s guide<\/em>, Free Software Foundation.<\/li>\n<li style=\"text-align: justify;\">Arnold. Robbins. 2002. <em>Sed &amp;amp; awk\u202f: pocket reference<\/em>, O\u2019Reilly.<\/li>\n<li style=\"text-align: justify;\">Theodore. Romoser and Michael R. Rose. 1972. <em>Awk.: a guide to<\/em> <em>effective writing<\/em>, Canfield Press.<\/li>\n<\/ol>\n<p><strong>Online Tutorials:<\/strong><\/p>\n<ol>\n<li>https:\/\/<em>www<\/em>.cse.iitb.ac.in\/~br\/courses\/cs699-autumn2013\/refs\/awk-tutorial.html<\/li>\n<li>http:\/\/www.theunixschool.com\/p\/awk-sed.html<\/li>\n<\/ol>\n","protected":false},"author":4,"menu_order":25,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["mr-hardik-joshi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-357","chapter","type-chapter","status-publish","hentry","contributor-mr-hardik-joshi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":7,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/357\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/357\/revisions\/708"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/357\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapter-type?post=357"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/contributor?post=357"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/license?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}