<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Linux%2FC3%2FBasics-of-awk%2FKhasi</id>
		<title>Linux/C3/Basics-of-awk/Khasi - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Linux%2FC3%2FBasics-of-awk%2FKhasi"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Linux/C3/Basics-of-awk/Khasi&amp;action=history"/>
		<updated>2026-04-11T02:17:56Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Linux/C3/Basics-of-awk/Khasi&amp;diff=42103&amp;oldid=prev</id>
		<title>Hezekiah2016: Created page with &quot;{| border=1 | '''Time''' | '''Narration'''  |- |  00:01 | Pdiang sngewbha sha kane ka spoken tutorial halor ka '''awk''' command.  |- |00:05  | Ha kane ka tutorial, ngin pule...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Linux/C3/Basics-of-awk/Khasi&amp;diff=42103&amp;oldid=prev"/>
				<updated>2018-02-02T11:58:52Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{| border=1 | &amp;#039;&amp;#039;&amp;#039;Time&amp;#039;&amp;#039;&amp;#039; | &amp;#039;&amp;#039;&amp;#039;Narration&amp;#039;&amp;#039;&amp;#039;  |- |  00:01 | Pdiang sngewbha sha kane ka spoken tutorial halor ka &amp;#039;&amp;#039;&amp;#039;awk&amp;#039;&amp;#039;&amp;#039; command.  |- |00:05  | Ha kane ka tutorial, ngin pule...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
| '''Time'''&lt;br /&gt;
| '''Narration'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:01&lt;br /&gt;
| Pdiang sngewbha sha kane ka spoken tutorial halor ka '''awk''' command.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:05 &lt;br /&gt;
| Ha kane ka tutorial, ngin pule iaka jingpyndonkam In this tutorial we will learn '''awk command.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:09&lt;br /&gt;
| We will do this through some examples.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:12&lt;br /&gt;
| To record this tutorial, I am using:&lt;br /&gt;
Ubuntu Linux 12.04 OS&lt;br /&gt;
GNU BASH v. 4.2.24&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:23&lt;br /&gt;
| Please note, GNU Bash version 4 or above is recommended to practice this tutorial.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:29&lt;br /&gt;
| Let us start with an introduction to '''awk'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:33&lt;br /&gt;
| The''' awk''' command is a very powerful text manipulation tool.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:38&lt;br /&gt;
| It is named after its authors, Aho, Weinberger and Kernighan.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:44&lt;br /&gt;
| It can perform several functions. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:46&lt;br /&gt;
| It operates at the field level of a record. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:51&lt;br /&gt;
| So, it can easily access and edit the individual fields of the record.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:56&lt;br /&gt;
| Let us see some examples. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:59&lt;br /&gt;
| For demonstration purpose, we use the '''awkdemo.txt''' file. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:04&lt;br /&gt;
| Let us see the contents of '''awkdemo.txt''' file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:09&lt;br /&gt;
| Now open the '''terminal''' window by pressing '''Ctrl + Alt''' and '''T''' keys simultaneously on your keyboard.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:17&lt;br /&gt;
| Let us see how to print using '''awk command.''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:22&lt;br /&gt;
| Type: '''awk space''' (within single quote) (front slash) ''' '/Pass '''(front slash)'''/'''(opening curly bracket) '''{print (closing curly bracket)}''' (after the  quotes) '''space awkdemo.txt''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:38&lt;br /&gt;
| Press '''Enter'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:40&lt;br /&gt;
|Here, '''Pass''' is the selection criteria. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:44&lt;br /&gt;
| All the lines of the '''awkdemo''' where '''Pass''' occurs are printed. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:49&lt;br /&gt;
| The action here is print. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:52&lt;br /&gt;
| We can also use '''regular expressions''' in '''awk'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:56&lt;br /&gt;
| Say, we want to print records of students with name &amp;quot;Mira.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:01&lt;br /&gt;
| We would type:&lt;br /&gt;
'''awk space '/M (opening square bracket) [ ei (closing square bracket) ]*ra */{print}' space awkdemo.txt'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:27&lt;br /&gt;
| Press '''Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:29&lt;br /&gt;
| ''' &amp;quot;*&amp;quot; '''  will give one or more occurrences of previous character.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:33&lt;br /&gt;
| Thus, entries with more than one occurrence for '''i, e''' and '''a''' will be listed.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:40&lt;br /&gt;
| For example, &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:42&lt;br /&gt;
| Mira with M I R A&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:45 &lt;br /&gt;
| Meera with M double E R A&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:47&lt;br /&gt;
| and Meeraa with M double E R double A&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:52&lt;br /&gt;
| '''awk''' supports the '''extended regular expressions (ERE)'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:58&lt;br /&gt;
| Which means we can match multiple patterns separated by a '''PIPE'''.&lt;br /&gt;
|-&lt;br /&gt;
|03:03&lt;br /&gt;
|Let me clear the prompt.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:05&lt;br /&gt;
|Now type:  '''awk space (within single quotes)(front slash) ‘/civil(PIPE) |electrical'''(front slash)'''space (opening curly brackets)/{print}(closing curly brackets)''' after the quotes space'''awkdemo.txt'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:23&lt;br /&gt;
| Press '''Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:26&lt;br /&gt;
| Now entries for both &amp;quot;civil&amp;quot; and &amp;quot;electrical&amp;quot; are given.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:31&lt;br /&gt;
|  Let us go back to our slides. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:34&lt;br /&gt;
| Parameters: '''awk''' has some special parameters to identify individual fields of a line. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:41&lt;br /&gt;
| '''$1(Dollar 1)''' would indicate the first field. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:45&lt;br /&gt;
| Similarly we can have '''$2, $3''' and so on for respective fields. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:53&lt;br /&gt;
| '''$0''' represents the entire line.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:56&lt;br /&gt;
|come back to our terminal.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:59&lt;br /&gt;
|Note that each word is separated by '''PIPE''' in the file '''awkdemo.txt.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:05&lt;br /&gt;
| In this case '''PIPE '''is called a '''delimiter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:09&lt;br /&gt;
| A '''delimiter''' separates words from each other.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:13&lt;br /&gt;
| A '''delimiter''' can also be a single '''white space.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:16&lt;br /&gt;
| To specify a '''delimiter''', we have to give '''- capital F flag''' followed by a '''delimiter'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:24&lt;br /&gt;
| Let us see.  Type: '''awk space minus capital F space''' within double quotes ''' PIPE space''' within single quote '''front-slash civil PIPE electrical front-slash''' opening curly bracket '''print space dollar0 closing curly bracket  after the quotes space awkdemo.txt'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:51&lt;br /&gt;
| Press '''Enter'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:53&lt;br /&gt;
| This prints the entire line since we have used '''$0.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:58&lt;br /&gt;
| Notice that '''names''' and '''stream of students''' are the second and third fields.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:04&lt;br /&gt;
|Say we only want to print two fields.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:08&lt;br /&gt;
| We will replace '''$0''' with '''$2 and $3''' in the above command.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:15&lt;br /&gt;
| Press '''Enter '''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:18&lt;br /&gt;
| Only two fields are shown.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:21&lt;br /&gt;
| Though it gives the right result, the display is all jagged and un-formatted. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:26&lt;br /&gt;
|  We can provide formatted output by using the '''C''' style '''printf '''statement. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:32&lt;br /&gt;
| We can also provide a serial number by using a built-in variable '''NR'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:40&lt;br /&gt;
| We will see more about built-in variables later.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:44&lt;br /&gt;
| Now Type '''awk''' space '''minus capital F within double quotes (Pipe)''' after the double quotes space ''' 'front-slash Pass front slash opening curly bracket printf (within double quotes)  &amp;quot;percentage sign 4d space percentage sign -25s space percentage sign  minus 15s space backslash n”,''' after the double quotes  '''NR, $2, $3 closing curly bracket' ''' after the single quote space '''awkdemo.txt'''  &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:33&lt;br /&gt;
| Press '''Enter.'''  We see the difference.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:37&lt;br /&gt;
| Here,  '''NR''' stands for number of records. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:41&lt;br /&gt;
| Records are '''integers''', hence we have written '''%d'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:45&lt;br /&gt;
| '''Name''' and '''Stream''' are '''strings'''. So we have used '''%s'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:50&lt;br /&gt;
| Here '''25s''' will reserve 25 '''spaces''' for '''Name''' field.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:55&lt;br /&gt;
| '''15s''' will reserve 15 '''spaces''' for '''Stream''' field.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:01&lt;br /&gt;
| The '''minus sign''' is used to left justify the output.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:05&lt;br /&gt;
| This brings us to the end of this tutorial.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:08&lt;br /&gt;
| Let us move back to our slides.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:10&lt;br /&gt;
| Let us summarize.  In this tutorial we learnt: * To print using awk&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:16&lt;br /&gt;
| Regular expression in awk * To list the entries for a particular stream&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:21&lt;br /&gt;
| To list only the second and the third fields&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:24&lt;br /&gt;
| To display a formatted output.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:28&lt;br /&gt;
| As an assignment,  display '''roll no., stream''' and '''marks''' of Ankit Saraf.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:34&lt;br /&gt;
|  Watch the video available at the link shown below.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:37&lt;br /&gt;
| It summarizes the Spoken Tutorial project.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:40&lt;br /&gt;
| If you do not have good bandwidth, you can download and watch it.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:45&lt;br /&gt;
|The Spoken Tutorial Project Team: Conducts workshops using spoken tutorials.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:48&lt;br /&gt;
| Gives certificates to those who pass an online test.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:52&lt;br /&gt;
| For more details, please write to contact@spoken-tutorial.org&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:58&lt;br /&gt;
|Spoken Tutorial Project is a part of the Talk to a Teacher project.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:01&lt;br /&gt;
| It is supported by the National Mission on Education through ICT,MHRD,Government of India.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:07&lt;br /&gt;
| More information on this Mission is available at:  [http://spokentutorial.org\NMEICT-Intro]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:12&lt;br /&gt;
|This is Ashwini Patil from IIT Bombay, signning off. Thank you for joining.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Hezekiah2016</name></author>	</entry>

	</feed>