Difference between revisions of "BOSS-Linux/C3/Basics-of-awk/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border=1 | '''Time''' | '''Narration''' |- | 00:01 | Welcome to the spoken tutorial on the '''awk''' command. |- |00:05 | In this tutorial we will learn, '''awk comman...")
 
 
(6 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
|-
 
|-
 
|  00:01
 
|  00:01
| Welcome to the spoken tutorial on the '''awk''' command.
+
| Welcome to the '''spoken tutorial''' on the '''awk''' command.
  
 
|-
 
|-
 
|00:05  
 
|00:05  
|  In this tutorial we will learn, '''awk command.'''
+
|  In this tutorial, we will learn ''''awk' command.'''
  
 
|-
 
|-
Line 17: Line 17:
 
|-
 
|-
 
| 00:12
 
| 00:12
| To record this tutorial, I am using
+
|To record this tutorial, I am using:
* Linux  Operating system
+
Linux  Operating system
*GNU BASH v. 4.2.24
+
GNU BASH v. 4.2.24
  
 
|-
 
|-
Line 43: Line 43:
 
|-
 
|-
 
| 00:46
 
| 00:46
| It operates at the field level of a record.  
+
| It operates at the '''field''' level of a '''record'''.  
  
 
|-
 
|-
 
| 00:49
 
| 00:49
| So, it can easily access and edit the individual fields of the record.
+
| So, it can easily access and edit the individual '''field'''s of the '''record'''.
  
 
|-
 
|-
Line 63: Line 63:
 
|-
 
|-
 
| 01:07
 
| 01:07
| Now open the '''terminal''' window
+
| Now, open the '''terminal window'''.
  
 
|-
 
|-
 
| 01:10
 
| 01:10
| Let us see how to print using '''awk command.'''  
+
| Let us see how to print using ''''awk' command.'''  
  
 
|-
 
|-
 
| 01:15
 
| 01:15
| Type: '''awk space''' (within single quote) (front slash) ‘'''/Pass '''(front slash)'''/'''(opening curly bracket) '''{print (closing curly bracket)}''' (after the  quotes) '''space awkdemo.txt'''  
+
| Type: '''awk space''' within single quote front-slash '''Pass ''' front- slash opening curly bracket '''print''' closing curly bracket (after the  quotes) '''space awkdemo.txt'''  
  
 
|-
 
|-
 
| 01:32
 
| 01:32
| Press '''Enter'''
+
| press '''Enter'''.
  
 
|-
 
|-
 
| 01:34
 
| 01:34
|Here '''Pass''' is the selection criteria.  
+
|Here, '''Pass''' is the selection criteria.  
  
 
|-
 
|-
Line 87: Line 87:
 
|-
 
|-
 
| 01:43
 
| 01:43
| The action here is print.  
+
| The action here is '''print'''.  
  
 
|-
 
|-
 
| 01:46
 
| 01:46
| We can also use '''regular expressions''' in '''awk'''
+
| We can also use '''regular expressions''' in '''awk'''.
  
 
|-
 
|-
 
| 01:50
 
| 01:50
| Say we want to print records of students with name '''Mira.'''
+
| Say, we want to print records of students with name '''Mira.'''
  
 
|-
 
|-
 
| 01:55
 
| 01:55
| We would type: '''awk space '/M opening square bracket ei closing square bracket asterisk sign ra asterisk sign front slash opening curly bracket  print closing curly bracket after the quoates space awkdemo.txt'''
+
| We would type: '''awk space''' within single quotes front-slash capital '''M''' (/M) opening square-bracket ''' ei''' closing square-bracket asterisk-sign '''ra''' asterisk-sign front-slash space opening curly-bracket  '''print''' closing-curly bracket after the quotes '''space awkdemo.txt'''
  
 
|-
 
|-
Line 107: Line 107:
 
|-
 
|-
 
| 02:22
 
| 02:22
| '''"*(asterisk)"'''  will give one or more occurrences of previous character.
+
| '''(asterisk)'''  will give one or more occurrences of previous character.
  
 
|-
 
|-
 
| 02:27
 
| 02:27
| Thus entries with more than one occurrence for '''i, e''' and '''a''' will be listed.
+
| Thus, entries with more than one occurrence for '''i, e''' and '''a''' will be listed.
  
 
|-
 
|-
 
| 02:34
 
| 02:34
| For example  
+
| For example- Mira (with 'M'  'I'  'R'  'A')
 
+
|-
+
| 02:35
+
| Mira (with 'M'  'I'  'R'  'A')
+
  
 
|-
 
|-
Line 127: Line 123:
 
|-
 
|-
 
| 02:41
 
| 02:41
| *Meeraa(with M E E R A A )
+
| Meeraa(with M E E R A A )
  
 
|-
 
|-
 
| 02:45
 
| 02:45
| '''awk''' supports the '''extended regular expressions (ERE)'''.
+
| '''awk''' supports the '''extended regular expressions (ERE)'''
  
 
|-
 
|-
 
| 02:51
 
| 02:51
| Which means we can match multiple patterns separated by a '''PIPE'''.
+
| which means we can match multiple patterns separated by a '''PIPE'''.
  
 
|-
 
|-
 
|02:56
 
|02:56
|Let me clear the promt
+
|Let me clear the prompt.
  
 
|-
 
|-
 
|02:59
 
|02:59
|Now type:
+
|Now, type: '''awk space within single quotes front slash civil PIPE (|) electrical front slash space opening curly bracket print closing curly bracket''' after the quotes '''space awkdemo.txt'''
 
+
|-
+
| 03:00
+
| '''awk space (in single quotes)(front slash) ‘/civil(PIPE) '''|electrical '''(front slash)'''space (open curly brackets)/{print}(close curly brackets) after the quotes space'''awkdemo.txt'''
+
  
 
|-
 
|-
 
| 03:18
 
| 03:18
| Press '''Enter.'''
+
| Press '''Enter.''' Now, entries for both '''civil''' and '''electrical''' are given.
 
+
|-
+
| 03:19
+
| Now entries for both '''civil''' and '''electrical''' are given.
+
  
 
|-
 
|-
Line 163: Line 151:
 
|-
 
|-
 
| 03:28
 
| 03:28
| Parameters '''awk''' has some special parameters to identify individual fields of a line.  
+
| Parameters: '''awk''' has some special parameters to identify individual fields of a line.  
  
 
|-
 
|-
 
| 03:36
 
| 03:36
| '''$1(Dollar 1)''' would indicate the first field.  
+
| '''$1 (Dollar 1)''' would indicate the first '''field'''.  
  
 
|-
 
|-
 
| 03:40
 
| 03:40
| Similarly we can have '''$2, $3''' and so on for respective fields.  
+
| Similarly, we can have '''$2, $3''' and so on for respective fields.  
  
 
|-
 
|-
Line 179: Line 167:
 
|-
 
|-
 
|03:50
 
|03:50
|come back to our terminal
+
|come back to our '''terminal'''.
  
 
|-
 
|-
Line 187: Line 175:
 
|-
 
|-
 
| 03:59
 
| 03:59
| In this case '''PIPE '''is called a '''delimiter.'''
+
| In this case, '''PIPE '''is called a '''delimiter.'''
  
 
|-
 
|-
 
| 04:03
 
| 04:03
| A '''delimiter''' separates words from each other.
+
| A delimiter separates words from each other.
  
 
|-
 
|-
 
| 04:06
 
| 04:06
| A '''delimiter''' can also be a single '''whitespace. '''
+
| A delimiter can also be a single '''white space.'''
  
 
|-
 
|-
 
| 04:11
 
| 04:11
| To specify a '''delimiter''', we have to give '''- capital F '''flag followed by a '''delimiter'''.
+
| To specify a '''delimiter''', we have to give '-F' (capital F) '''flag''' followed by a delimiter. Let us see.
 
+
|-
+
|04:18
+
| Let us see  
+
  
 
|-
 
|-
 
| 04:19
 
| 04:19
| 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 braket after the quotes space awkdemo.txt'''
+
| 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'''
  
 
|-
 
|-
 
| 04:44
 
| 04:44
| Press '''Enter'''
+
| Press '''Enter'''.
  
 
|-
 
|-
 
| 04:46
 
| 04:46
| This print the entire line since we have used '''$0.'''
+
| This prints the entire line since we have used '''$0.'''
  
 
|-
 
|-
 
| 04:52
 
| 04:52
| Notice that, '''names''' and '''stream of students''' are the second and third fields.
+
| Notice that '''names''' and '''stream''' of students are the second and third fields.
  
 
|-
 
|-
 
| 04:58
 
| 04:58
|Say we only want to print two fields.
+
|Say, we only want to print two fields.
  
 
|-
 
|-
 
| 05:01
 
| 05:01
| We will replace '''$0''' with '''$2 and$3''' in the above command.
+
| We will replace '''$0''' with '''$2''' and '''$3''' in the above '''command'''.
  
 
|-
 
|-
 
| 05:09
 
| 05:09
| Press '''Enter '''
+
| Press '''Enter '''.
  
 
|-
 
|-
Line 239: Line 223:
 
|-
 
|-
 
| 05:14
 
| 05:14
| Though it gives the right result, the display is all jagged and unformatted.  
+
| Though it gives the right result, the display is all jagged and un-formatted.  
  
 
|-
 
|-
Line 255: Line 239:
 
|-
 
|-
 
| 05:37
 
| 05:37
| 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  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'''  
+
| 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  percentage- sign 4d space percentage-sign -25s  space percentage-sign minus 15s space backslash n''', after the double quotes comma '''NR, $2, $3 closing curly bracket'''' after the single quote space '''awkdemo.txt'''  
  
 
|-
 
|-
Line 267: Line 251:
 
|-
 
|-
 
| 06:30
 
| 06:30
| Here the '''NR''' stands for number of records.  
+
| Here'''NR''' stands for number of records.  
  
 
|-
 
|-
Line 279: Line 263:
 
|-
 
|-
 
| 06:43
 
| 06:43
| Here '''25s''' will reserve 25 spaces for '''Name''' field.
+
| Here, '''25s''' will reserve 25 spaces for '''Name''' field.
  
 
|-
 
|-
Line 299: Line 283:
 
|-
 
|-
 
| 07:04
 
| 07:04
| Let us summarize.
+
| Let us summarize. In this tutorial, we learntTo print using '''awk'''
 
+
|-
+
| 07:05
+
| In this tutorial we learnt To print using '''awk'''
+
  
 
|-
 
|-
 
| 07:10
 
| 07:10
| Regular expression in '''awk'''. To list the enteries for a paritcular stream
+
| Regular expression in '''awk''' To list the entries for a particular stream
  
 
|-
 
|-
 
| 07:15
 
| 07:15
| To list only the second and the third fileds
+
| To list only the second and the third fields
 
+
|-
+
| 07:18
+
| To display a formatted output
+
  
 
|-
 
|-
| 07:19
+
|07:18
| As an assignment  
+
| To display a formatted output. As an assignment,
  
 
|-
 
|-
 
|07:22  
 
|07:22  
| Display roll no., stream and marks of Ankti Saraf
+
| Display '''roll no., stream''' and '''marks''' of Ankti Saraf
  
 
|-
 
|-
 
| 07:27
 
| 07:27
|  Watch the video available at the link shown below
+
|  Watch the video available at the link shown below.
  
 
|-
 
|-
 
| 07:30
 
| 07:30
| It summarises the Spoken Tutorial project
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
| 07:33
 
| 07:33
| If you do not have good bandwidth, you can download and watch it
+
| If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
 
|07:37
 
|07:37
|The Spoken Tutorial Project Team Conducts workshops using spoken tutorials
+
|The Spoken Tutorial Project Team: Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 07:42
 
| 07:42
| Gives certificates to those who pass an online test
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 351: Line 327:
 
|-
 
|-
 
| 07:51
 
| 07:51
|Spoken Tutorial Project is a part of the Talk to a Teacher project
+
|'''Spoken Tutorial''' Project is a part of the '''Talk to a Teacher''' project.
  
 
|-
 
|-
 
| 07:55
 
| 07:55
| It is supported by the National Mission on Education through ICT,MHRD,Government of India
+
| It is supported by the National Mission on Education through ICT,MHRD,Government of India.
  
 
|-
 
|-
 
| 08:02
 
| 08:02
| More information on this Mission is available at:  [http://spokentutorial.org\NMEICT-Intro]
+
| More information on this mission is available at:  [http://spokentutorial.org\NMEICT-Intro]
  
 
|-
 
|-
 
| 08:07
 
| 08:07
|This is Ashwini Patil from IIT Bombay signning off. Thank you for joining.
+
|This is Ashwini Patil from IIT Bombay, signing off. Thank you for joining.
  
 
|}
 
|}

Latest revision as of 12:42, 24 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on the awk command.
00:05 In this tutorial, we will learn 'awk' command.
00:09 We will do this through some examples.
00:12 To record this tutorial, I am using:

Linux Operating system GNU BASH v. 4.2.24

00:21 Please note, GNU Bash version 4 or above is recommended to practice this tutorial.
00:29 Let us start with an introduction to awk.
00:32 The awk command is a very powerful text manipulation tool.
00:36 It is named after its authors, Aho, Weinberger and Kernighan.
00:42 It can perform several functions.
00:46 It operates at the field level of a record.
00:49 So, it can easily access and edit the individual fields of the record.
00:56 Let us see some examples.
00:58 For demonstration purpose, we use the awkdemo.txt file.
01:03 Let us see the contents of awkdemo.txt file.
01:07 Now, open the terminal window.
01:10 Let us see how to print using 'awk' command.
01:15 Type: awk space within single quote front-slash Pass front- slash opening curly bracket print closing curly bracket (after the quotes) space awkdemo.txt
01:32 press Enter.
01:34 Here, Pass is the selection criteria.
01:38 All the lines of the awkdemo where Pass occurs are printed.
01:43 The action here is print.
01:46 We can also use regular expressions in awk.
01:50 Say, we want to print records of students with name Mira.
01:55 We would type: awk space within single quotes front-slash capital M (/M) opening square-bracket ei closing square-bracket asterisk-sign ra asterisk-sign front-slash space opening curly-bracket print closing-curly bracket after the quotes space awkdemo.txt
02:20 Press Enter.
02:22 (asterisk) will give one or more occurrences of previous character.
02:27 Thus, entries with more than one occurrence for i, e and a will be listed.
02:34 For example- Mira (with 'M' 'I' 'R' 'A')
02:38 Meera(with 'M' 'E' 'E' 'R' 'A')
02:41 Meeraa(with M E E R A A )
02:45 awk supports the extended regular expressions (ERE)
02:51 which means we can match multiple patterns separated by a PIPE.
02:56 Let me clear the prompt.
02:59 ) electrical front slash space opening curly bracket print closing curly bracket after the quotes space awkdemo.txt
03:18 Press Enter. Now, entries for both civil and electrical are given.
03:24 Let us go back to our slides.
03:28 Parameters: awk has some special parameters to identify individual fields of a line.
03:36 $1 (Dollar 1) would indicate the first field.
03:40 Similarly, we can have $2, $3 and so on for respective fields.
03:47 $0 represents the entire line.
03:50 come back to our terminal.
03:52 Note that each word is separated by PIPE in the file awkdemo.txt.
03:59 In this case, PIPE is called a delimiter.
04:03 A delimiter separates words from each other.
04:06 A delimiter can also be a single white space.
04:11 To specify a delimiter, we have to give '-F' (capital F) flag followed by a delimiter. Let us see.
04:19 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
04:44 Press Enter.
04:46 This prints the entire line since we have used $0.
04:52 Notice that names and stream of students are the second and third fields.
04:58 Say, we only want to print two fields.
05:01 We will replace $0 with $2 and $3 in the above command.
05:09 Press Enter .
05:11 Only two fields are shown.
05:14 Though it gives the right result, the display is all jagged and un-formatted.
05:20 We can provide formatted output by using the C style printf statement.
05:26 We can also provide a serial number by using a builtin variable NR.
05:33 We will see more about builtin variables later.
05:37 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 percentage- sign 4d space percentage-sign -25s space percentage-sign minus 15s space backslash n, after the double quotes comma NR, $2, $3 closing curly bracket' after the single quote space awkdemo.txt
06:25 Press Enter.
06:28 We see the difference.
06:30 Here, NR stands for number of records.
06:33 Records are integers, hence we have written %d.
06:37 Name and Stream are strings. So we have used %s.
06:43 Here, 25s will reserve 25 spaces for Name field.
06:48 15s will reserve 15 spaces for Stream field.
06:54 The minus sign is used to left justify the output.
06:58 This brings us to the end of this tutorial.
07:01 Let us move back to our slides.
07:04 Let us summarize. In this tutorial, we learnt: To print using awk
07:10 Regular expression in awk To list the entries for a particular stream
07:15 To list only the second and the third fields
07:18 To display a formatted output. As an assignment,
07:22 Display roll no., stream and marks of Ankti Saraf
07:27 Watch the video available at the link shown below.
07:30 It summarizes the Spoken Tutorial project.
07:33 If you do not have good bandwidth, you can download and watch it.
07:37 The Spoken Tutorial Project Team: Conducts workshops using spoken tutorials.
07:42 Gives certificates to those who pass an online test.
07:45 For more details, please write to contact@spoken-tutorial.org
07:51 Spoken Tutorial Project is a part of the Talk to a Teacher project.
07:55 It is supported by the National Mission on Education through ICT,MHRD,Government of India.
08:02 More information on this mission is available at: [1]
08:07 This is Ashwini Patil from IIT Bombay, signing off. Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14