{"id":2434,"date":"2017-01-11T17:15:03","date_gmt":"2017-01-11T15:15:03","guid":{"rendered":"http:\/\/www.systemcodegeeks.com\/?p=2434"},"modified":"2017-12-04T15:49:17","modified_gmt":"2017-12-04T13:49:17","slug":"linux-bash-awk-example","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/","title":{"rendered":"Linux Bash awk Example"},"content":{"rendered":"<p>This is an awk tutorial. The basic function of awk is to search files for lines or other text units containing one or more patterns.<\/p>\n<p>When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are &#8220;data-driven&#8221;. You describe the data you want to work with and then what to do when you find it.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;SG9vnnKgRCD7iZxf&#8217;]<br \/>\n&nbsp;<br \/>\nMost other languages are &#8220;procedural.&#8221; You have to describe, in great detail, every step the program is to take. When working with procedural languages, it is usually much harder to clearly describe the data your program will process.<\/p>\n<p>For this reason, awk programs are often refreshingly easy to read and write.<\/p>\n<p>The following table shows an overview of the whole article:<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#intro\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#print\">2. The print Program<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#print_sel\">2.1 Printing selected fields<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#print_form\">2.2 Formatting fields<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#print_reg\">2.3 The print command and regular expressions<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#print_patt\">2.4 Special patterns<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#print_script\">2.5 awk Scripts<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#variables\">3. awk Variables<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#variables_inp\">3.1 The input field separator<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#variables_out\">3.2 The output separators<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#variables_number\">3.3 The number of records<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#summary\">4. Summary<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"intro\"><\/a>1. Introduction<\/h2>\n<p>When you run awk, you specify an awk program that tells awk what to do. The program consists of a series of rules. It may also contain function definitions, loops, conditions and other programming constructs, advanced features that we will ignore for now.<\/p>\n<p>Each rule specifies one pattern to search for and one action to perform upon finding the pattern.<\/p>\n<p>There are several ways to run awk. If the program is short, it is easiest to run it on the command line:<\/p>\n<pre class=\"brush:xml\">awk PROGRAM inputfile(s)\r\n<\/pre>\n<p>If multiple changes have to be made, possibly regularly and on multiple files, it is easier to put the awk commands in a script.<\/p>\n<p>This is read like this:<\/p>\n<pre class=\"brush:xml\">awk -f PROGRAM-FILE inputfile(s)\r\n<\/pre>\n<h2><a name=\"print\"><\/a>2. The print Program<\/h2>\n<h3><a name=\"print_sel\"><\/a>2.1 Printing selected fields<\/h3>\n<p>The print command in awk outputs selected data from the input file. When awk reads a line of a file, it divides the line in fields based on the specified input field separator, FS, which is an awk variable. This variable is predefined to be one or more spaces or tabs.<\/p>\n<p>The variables $1, $2, $3, &#8230;, $N hold the values of the first, second, third until the last field of an input line.<\/p>\n<p>The variable $0 (zero) holds the value of the entire line.<\/p>\n<pre class=\"brush:xml\">ls -l | awk '{ print $5 $9 }'\r\n<\/pre>\n<p>In the output of ls -l, there are 9 columns. The print statement uses these fields as follows:<\/p>\n<figure id=\"attachment_2443\" aria-describedby=\"caption-attachment-2443\" style=\"width: 541px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2443\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample1.jpg\" alt=\"Printing selected fields with awk\" width=\"541\" height=\"347\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample1.jpg 541w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample1-300x192.jpg 300w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/a><figcaption id=\"caption-attachment-2443\" class=\"wp-caption-text\">Printing selected fields with awk<\/figcaption><\/figure>\n<p>This command printed the fifth column of a long file listing, which contains the file size, and the last column, the name of the file. This output is not very readable unless you use the official way of referring to columns, which is to separate the ones that you want to print with a comma. In that case, the default output separater character, usually a space, will be put in between each output field.<\/p>\n<h3><a name=\"print_form\"><\/a>2.2 Formatting fields<\/h3>\n<p>Without formatting, using only the output separator, the output looks rather poor. Inserting a couple of tabs and a string to indicate what output this is will make it look a lot better:<\/p>\n<pre class=\"brush:xml\">ls -ldh * | grep -v total | \\\r\nawk '{ print \"Size is \" $5 \" bytes for \" $9 }'\r\n<\/pre>\n<figure id=\"attachment_2444\" aria-describedby=\"caption-attachment-2444\" style=\"width: 551px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2444\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample2.jpg\" alt=\"Formatting fields with awk\" width=\"551\" height=\"347\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample2.jpg 551w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample2-300x189.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/a><figcaption id=\"caption-attachment-2444\" class=\"wp-caption-text\">Formatting fields with awk<\/figcaption><\/figure>\n<p>Note the use of the backslash, which makes long input continue on the next line without the shell interpreting this as a separate command. While your command line input can be of virtually unlimited length, your monitor is not, and printed paper certainly isn&#8217;t.<\/p>\n<p>Using the backslash also allows for copying and pasting of the above lines into a terminal window.<\/p>\n<p>The -h option to ls is used for supplying humanly readable size formats for bigger files. The output of a long listing displaying the total amount of blocks in the directory is given when a directory is the argument.<\/p>\n<p>This line is useless to us, so we add an asterisk. We also add the -d option for the same reason, in case asterisk expands to a directory.<\/p>\n<p>The backslash in this example marks the continuation of a line.<\/p>\n<h3><a name=\"print_reg\"><\/a>2.3 The print command and regular expressions<\/h3>\n<p>A regular expression can be used as a pattern by enclosing it in slashes. The regular expression is then tested against the entire text of each record. The syntax is as follows:<\/p>\n<pre class=\"brush:xml\">awk 'EXPRESSION { PROGRAM }' file(s)\r\n<\/pre>\n<p>Below another example where we search the current directory for files ending in &#8220;.txt&#8221; and starting with either &#8220;i&#8221; or &#8220;o&#8221;, using extended regular expressions:<\/p>\n<pre class=\"brush:xml\">ls -l | awk '\/\\&lt;(i|o).*\\.txt$\/ { print $9 }'\r\n<\/pre>\n<figure id=\"attachment_2445\" aria-describedby=\"caption-attachment-2445\" style=\"width: 551px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample3.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2445\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample3.jpg\" alt=\"Using Regular Expressions with awk\" width=\"551\" height=\"307\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample3.jpg 551w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample3-300x167.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/a><figcaption id=\"caption-attachment-2445\" class=\"wp-caption-text\">Using Regular Expressions with awk<\/figcaption><\/figure>\n<p>This example illustrates the special meaning of the dot in regular expressions: the first one indicates that we want to search for any character after the first search string, the second is escaped because it is part of a string to find (the end of the file name).<\/p>\n<h3><a name=\"print_patt\"><\/a>2.4 Special patterns<\/h3>\n<p>In order to precede output with comments, use the <code>BEGIN<\/code> statement:<\/p>\n<pre class=\"brush:xml\">ls -l | \\\r\nawk 'BEGIN { print \"Files found:\\n\" } \/\\&lt;[a|x].*\\.txt$\/ { print $9 }'\r\n<\/pre>\n<figure id=\"attachment_2446\" aria-describedby=\"caption-attachment-2446\" style=\"width: 551px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample4.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2446\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample4.jpg\" alt=\"Using special patterns with awk\" width=\"551\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample4.jpg 551w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample4-300x178.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/a><figcaption id=\"caption-attachment-2446\" class=\"wp-caption-text\">Using special patterns with awk<\/figcaption><\/figure>\n<p>The <code>END<\/code> statement can be added for inserting text after the entire input is processed:<\/p>\n<pre class=\"brush:xml\">ls -l | \\\r\nawk '\/\\&lt;[a|x].*\\.txt$\/ { print $9 } END { print \\\r\n\"Can I do anything else for you, mistress?\" }'\r\n<\/pre>\n<figure id=\"attachment_2447\" aria-describedby=\"caption-attachment-2447\" style=\"width: 551px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample5.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2447\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample5.jpg\" alt=\"Using special patterns with awk\" width=\"551\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample5.jpg 551w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample5-300x178.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/a><figcaption id=\"caption-attachment-2447\" class=\"wp-caption-text\">Using special patterns with awk<\/figcaption><\/figure>\n<h3><a name=\"print_script\"><\/a>2.5 awk Scripts<\/h3>\n<p>As commands tend to get a little longer, you might want to put them in a script, so they are reusable. An awk script contains awk statements defining patterns and actions.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>filerep.awk<\/em><\/span><\/p>\n<pre class=\"brush:xml\">BEGIN { print \"*** Information ***\" }\r\n\/\\&lt;[a|x].*\\.txt$\/ { print \"File \" $9 \"\\t: \" $5 \" Bytes!\" }\r\nEND { print \"*** about Textfiles and their size ***\" }\r\n<\/pre>\n<p>The following command executes the script:<\/p>\n<pre class=\"brush:xml\">ls -l | awk -f filerep.awk\r\n<\/pre>\n<figure id=\"attachment_2448\" aria-describedby=\"caption-attachment-2448\" style=\"width: 551px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample6.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2448\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample6.jpg\" alt=\"An awk script Example\" width=\"551\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample6.jpg 551w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample6-300x178.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/a><figcaption id=\"caption-attachment-2448\" class=\"wp-caption-text\">An awk script Example<\/figcaption><\/figure>\n<p>awk first prints a begin message, then formats all the lines that contain an eight or a nine at the beginning of a word, followed by one other number and a percentage sign. An end message is added.<\/p>\n<h2><a name=\"variables\"><\/a>3. awk Variables<\/h2>\n<p>As awk is processing the input file, it uses several variables. Some are editable, some are read-only.<\/p>\n<h3><a name=\"variables_inp\"><\/a>3.1 The input field separator<\/h3>\n<p>The following file represents a list with the Id and Name of different persons:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Test1.txt<\/em><\/span><\/p>\n<pre class=\"brush:xml\">1:Andreas\r\n2:Marcus\r\n3:Tom\r\n4:Steve\r\n<\/pre>\n<p>The field separator, which is either a single character or a regular expression, controls the way awk splits up an input record into fields. The input record is scanned for character sequences that match the separator definition. The fields themselves are the text between the matches.<\/p>\n<p>The field separator is represented by the built-in variable FS. Note that this is something different from the IFS variable used by POSIX-compliant shells.<\/p>\n<p>The value of the field separator variable can be changed in the awk program with the assignment operator =.<\/p>\n<p>Often the right time to do this is at the beginning of execution before any input has been processed, so that the very first record is read with the proper separator. To do this, use the special <code>BEGIN<\/code> pattern.<\/p>\n<p>In the example below, we build a command that displays all the users on your system with a description:<\/p>\n<figure id=\"attachment_2449\" aria-describedby=\"caption-attachment-2449\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample7.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2449\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample7.jpg\" alt=\"An awk input field separator Example\" width=\"531\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample7.jpg 531w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample7-300x185.jpg 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-2449\" class=\"wp-caption-text\">An awk input field separator Example<\/figcaption><\/figure>\n<h3><a name=\"variables_out\"><\/a>3.2 The output separators<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>Test2.txt<\/em><\/span><\/p>\n<p>The following file represents a list with the Id and Name of different persons. The separator will be represented by a Tabulator in this case:<\/p>\n<pre class=\"brush:xml\">1       Andreas\r\n2       Marcus\r\n3       Tom\r\n4       Steve\r\n<\/pre>\n<h4><a name=\"variables_out_fsep\"><\/a>3.2.1 The output field separator<\/h4>\n<p>Fields are normally separated by spaces in the output. This becomes apparent when you use the correct syntax for the print command, where arguments are separated by commas:<\/p>\n<figure id=\"attachment_2450\" aria-describedby=\"caption-attachment-2450\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample8.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2450\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample8.jpg\" alt=\"An awk output field separator Example\" width=\"531\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample8.jpg 531w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample8-300x185.jpg 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-2450\" class=\"wp-caption-text\">An awk output field separator Example<\/figcaption><\/figure>\n<p>If you don&#8217;t put in the commas, print will treat the items to output as one argument, thus omitting the use of the default output separator, OFS.<\/p>\n<h4><a name=\"variables_out_rsep\"><\/a>3.2.2 The output record separator<\/h4>\n<p>The output from an entire print statement is called an output record. Each print command results in one output record, and then outputs a string called the output record separator, ORS.<\/p>\n<p>The default value for this variable is &#8220;\\n&#8221;, a newline character. Thus, each print statement generates a separate line.<\/p>\n<p>To change the way output fields and records are separated, assign new values to OFS and ORS:<\/p>\n<figure id=\"attachment_2451\" aria-describedby=\"caption-attachment-2451\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample9.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2451\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample9.jpg\" alt=\"An awk output record separator Example\" width=\"531\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample9.jpg 531w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample9-300x185.jpg 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-2451\" class=\"wp-caption-text\">An awk output record separator Example<\/figcaption><\/figure>\n<h3><a name=\"variables_number\"><\/a>3.3 The number of records<\/h3>\n<p>The built-in NR holds the number of records that are processed. It is incremented after reading a new input line. You can use it at the end to count the total number of records, or in each output record:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>records.awk<\/em><\/span><\/p>\n<pre class=\"brush:xml\">BEGIN { OFS=\"-\" ; ORS=\"\\n--&gt; done\\n\" }\r\n{ print \"Record number \" NR \":\\t\" $1,$2 }\r\nEND { print \"Number of records processed: \" NR }\r\n<\/pre>\n<figure id=\"attachment_2452\" aria-describedby=\"caption-attachment-2452\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample10.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2452\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample10.jpg\" alt=\"Getting the number of records by using awk\" width=\"531\" height=\"327\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample10.jpg 531w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/01\/AwkExample10-300x185.jpg 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-2452\" class=\"wp-caption-text\">Getting the number of records by using awk<\/figcaption><\/figure>\n<h2><a name=\"summary\"><\/a>4. Summary<\/h2>\n<p>The awk utility interprets a special-purpose programming language, handling simple data-reformatting jobs with just a few lines of code. It is the free version of the general UNIX awk command.<\/p>\n<p>This tools reads lines of input data and can easily recognize columned output. The print program is the most common for filtering and formatting defined fields.<\/p>\n<p>On-the-fly variable declaration is straightforward and allows for simple calculation of sums, statistics and other operations on the processed input stream. Variables and commands can be put in awk scripts for background processing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an awk tutorial. The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are &hellip;<\/p>\n","protected":false},"author":35,"featured_media":185,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[107],"class_list":["post-2434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","tag-awk"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux Bash awk Example - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are &quot;data-driven&quot;.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux Bash awk Example - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are &quot;data-driven&quot;.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-11T15:15:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-04T13:49:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andreas Pomarolli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andreas Pomarolli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\"},\"author\":{\"name\":\"Andreas Pomarolli\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574\"},\"headline\":\"Linux Bash awk Example\",\"datePublished\":\"2017-01-11T15:15:03+00:00\",\"dateModified\":\"2017-12-04T13:49:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\"},\"wordCount\":1470,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"keywords\":[\"awk\"],\"articleSection\":[\"BASH\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\",\"name\":\"Linux Bash awk Example - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"datePublished\":\"2017-01-11T15:15:03+00:00\",\"dateModified\":\"2017-12-04T13:49:17+00:00\",\"description\":\"The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are \\\"data-driven\\\".\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shell Scripting\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"BASH\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/bash\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Linux Bash awk Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574\",\"name\":\"Andreas Pomarolli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g\",\"caption\":\"Andreas Pomarolli\"},\"description\":\"Andreas has graduated from Computer Science and Bioinformatics at the University of Linz. During his studies he has been involved with a large number of research projects ranging from software engineering to data engineering and at least web engineering. His scientific focus includes the areas of software engineering, data engineering, web engineering and project management. He currently works as a software engineer in the IT sector where she is mainly involved with projects based on Java, Databases and Web Technologies.\",\"sameAs\":[\"https:\/\/www.systemcodegeeks.com\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/andreas-pomarolli\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux Bash awk Example - System Code Geeks - 2026","description":"The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are \"data-driven\".","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/","og_locale":"en_US","og_type":"article","og_title":"Linux Bash awk Example - System Code Geeks - 2026","og_description":"The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are \"data-driven\".","og_url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_published_time":"2017-01-11T15:15:03+00:00","article_modified_time":"2017-12-04T13:49:17+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","type":"image\/jpeg"}],"author":"Andreas Pomarolli","twitter_card":"summary_large_image","twitter_creator":"@systemcodegeeks","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Andreas Pomarolli","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/"},"author":{"name":"Andreas Pomarolli","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574"},"headline":"Linux Bash awk Example","datePublished":"2017-01-11T15:15:03+00:00","dateModified":"2017-12-04T13:49:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/"},"wordCount":1470,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","keywords":["awk"],"articleSection":["BASH"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/","url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/","name":"Linux Bash awk Example - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","datePublished":"2017-01-11T15:15:03+00:00","dateModified":"2017-12-04T13:49:17+00:00","description":"The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. Programs in awk are different from programs in most other languages, because awk programs are \"data-driven\".","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/linux-bash-awk-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Shell Scripting","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/"},{"@type":"ListItem","position":3,"name":"BASH","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/bash\/"},{"@type":"ListItem","position":4,"name":"Linux Bash awk Example"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574","name":"Andreas Pomarolli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g","caption":"Andreas Pomarolli"},"description":"Andreas has graduated from Computer Science and Bioinformatics at the University of Linz. During his studies he has been involved with a large number of research projects ranging from software engineering to data engineering and at least web engineering. His scientific focus includes the areas of software engineering, data engineering, web engineering and project management. He currently works as a software engineer in the IT sector where she is mainly involved with projects based on Java, Databases and Web Technologies.","sameAs":["https:\/\/www.systemcodegeeks.com"],"url":"https:\/\/www.systemcodegeeks.com\/author\/andreas-pomarolli\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/2434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=2434"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/2434\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/185"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=2434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=2434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=2434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}