Difference between revisions of "BOSS-Linux/C3/The-grep-command/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(3 intermediate revisions by one other user not shown)
Line 5: Line 5:
 
|-
 
|-
 
|00:01
 
|00:01
|Welcome to the spoken tutorial on '''grep''' command
+
|Welcome to the spoken tutorial on '''grep''' command.
  
 
|-
 
|-
 
|00:05
 
|00:05
|In this tutorial we will learn '''grep command'''.
+
|In this tutorial, we will learn '''grep command'''.
  
 
|-
 
|-
Line 17: Line 17:
 
|-
 
|-
 
|00:12
 
|00:12
|To record this tutorial, I am using
+
|To record this tutorial, I am using:
  
 
|-
 
|-
 
|00:15
 
|00:15
|*''' Linux''' ''' Operating System'''  
+
|'''Linux''' ''' Operating System''' and
  
 
|-
 
|-
 
|00:18
 
|00:18
| and *'''GNU BASH''' version 4.2.24
+
|'''GNU BASH''' version 4.2.24
  
 
|-
 
|-
 
|00:22
 
|00:22
|Please note,''' GNU bash''' version 4 or above is recommended to practise this tutorial.
+
|Please note,''' GNU bash''' version 4 or above is recommended to practice this tutorial.
  
 
|-
 
|-
 
|00:30
 
|00:30
|As prerequisites You should know basics of '''Linux terminal'''
+
|As prerequisites, you should know basics of '''Linux terminal'''.
  
 
|-
 
|-
Line 41: Line 41:
 
|-
 
|-
 
|00:39
 
|00:39
|First let us know about regular expressions.
+
|First, let us know about ''' regular expressions''' .
  
 
|-
 
|-
 
|00:43
 
|00:43
|*Regular expressions are pattern matching techniques.
+
|* Regular expressions are pattern matching techniques.
  
 
|-
 
|-
 
|00:47
 
|00:47
|*When we have to find out whether a pattern exist in a line, paragraph or a file.
+
|* when we have to find out whether a pattern exists in a line, paragraph or a file.
  
 
|-
 
|-
Line 57: Line 57:
 
|-
 
|-
 
| 01:01
 
| 01:01
Or To find a keyword in a paragraph or a line, we use '''grep command'''
+
or to find a keyword in a paragraph or a line, we use '''grep command'''.
 
Let us move on to '''grep'''.
 
Let us move on to '''grep'''.
  
 
|-
 
|-
 
|01:08
 
|01:08
|'''grep''' searches for one or more patterns in one or more line, paragraph or a file.
+
|'''grep''' searches for one or more patterns in one or more lines, paragraph or a file.
  
 
|-
 
|-
 
|01:15
 
|01:15
|If filename is not mentioned,''' grep''' search for the patterns in the standard input.
+
|If file-name is not mentioned,''' grep''' searches for the patterns in the standard input.
  
 
|-
 
|-
Line 74: Line 74:
 
|-
 
|-
 
|01:28
 
|01:28
|I will demonstrate usage of '''grep''' using a demo file called '''grepdemo.txt'''
+
|I will demonstrate usage of '''grep''' using a demo file called '''grepdemo.txt'''.
  
 
|-
 
|-
Line 86: Line 86:
 
|-
 
|-
 
|01:41
 
|01:41
|Each entry has 6 fields roll number, name, stream, marks, and stipend amount.  
+
|Each entry has 6 '''field'''s- '''roll number, name, stream, marks''' and '''stipend amount'''.  
  
 
|-
 
|-
 
|01:50
 
|01:50
|The fields are separated by a bar, which is called a '''delimiter'''.
+
|The fields are separated by a bar which is called a '''delimiter'''.
  
 
|-
 
|-
Line 98: Line 98:
 
|-
 
|-
 
|01:58
 
|01:58
|Say we want to use '''grep command''', to see who are the students in the '''computers''' stream.
+
|Say, we want to use ''''grep' command''' to see who are the students in the '''computers''' stream.
  
 
|-
 
|-
 
|02:04
 
|02:04
|For this we have to open the '''terminal'''.
+
|For this, we have to open the '''terminal'''.
  
 
|-
 
|-
 
|02:07
 
|02:07
|Now type on the '''terminal''':
+
|Now, type on the terminal:
  
 
|-
 
|-
Line 114: Line 114:
 
|-
 
|-
 
|02:18
 
|02:18
|Press Enter
+
|Press Enter.
  
 
|-
 
|-
Line 122: Line 122:
 
|-
 
|-
 
|02:25
 
|02:25
|Now compare the result with the original file.  
+
|Now, compare the result with the original file.  
  
 
|-
 
|-
 
|02:29
 
|02:29
|Come back to our text editor.
+
|Come back to our '''text editor'''.
  
 
|-
 
|-
Line 138: Line 138:
 
|-
 
|-
 
|02:38
 
|02:38
|This is because '''grep''' searched for the pattern '''“computers”''' with small '''c'''  
+
|This is because '''grep''' searched for the pattern “computers” with small '''c'''  
  
 
|-
 
|-
 
|02:43
 
|02:43
|While for '''Zubin''', the stream is “Computers” with a capital '''C'''.
+
|while for '''Zubin''', the stream is “Computers” with a capital '''C'''.
  
 
|-
 
|-
Line 154: Line 154:
 
|-
 
|-
 
|02:58
 
|02:58
|Come back to our terminal Now Type:
+
|Come back to our terminal. Now, type:
'''grep space (minus) i  space (within double quotes) “'''computers”''' after the '''double quotes space grepdemo.txt'''
+
'''grep space minus i  space within double quotes computers after the double quotes space grepdemo.txt'''
  
 
|-
 
|-
 
|03:12
 
|03:12
|Press ''' Enter.'''
+
|Press ''' Enter.'''This will now enlist all the four entries.
 
+
|-
+
|03:13
+
|This will now enlist all the four entries.
+
  
 
|-
 
|-
Line 175: Line 171:
 
|-
 
|-
 
|03:26
 
|03:26
|It is possible to make '''grep''' enlist only those lines that '''do not''' match the pattern.
+
|It is possible to make '''grep''' enlist only those lines that do not match the pattern.
  
 
|-
 
|-
 
|03:32
 
|03:32
|For that we have the '''minus v''' option.
+
|For that, we have the '''minus v''' option.
  
 
|-
 
|-
Line 187: Line 183:
 
|-
 
|-
 
|03:40
 
|03:40
|We can also store this result in another file
+
|We can also store this result in another file.
  
 
|-
 
|-
 
|03:43
 
|03:43
|For this type:
+
|For this, type:
'''grep space minus iv space''' Within double quotes '''pass after the double quotes space grepdemo.txt space greater than sign space notpass.txt '''
+
'''grep space minus iv space''' within double quotes '''pass''' after the double quotes '''space grepdemo.txt space greater than sign space notpass.txt '''
  
 
|-
 
|-
Line 200: Line 196:
 
|-
 
|-
 
|04:04
 
|04:04
|To see the content of file, type: '''cat space notpass.txt '''
+
|To see the content of the file, type: '''cat space notpass.txt '''.
  
 
|-
 
|-
 
|04:11
 
|04:11
|Press '''Enter'''.
+
|Press '''Enter'''.The output is displayed.
 
+
|-
+
|04:12
+
|The output is displayed.
+
  
 
|-
 
|-
 
|04:15
 
|04:15
|Now at the '''prompt''' type:
+
|Now, at the '''prompt''', type:
  
 
|-
 
|-
 
|04:17
 
|04:17
|''grep space minus i space''' within double quotes '''fail''' after the double quotes space '''grepdemo.txt'''
+
|'''grep space minus i space''' within double quotes '''fail''' after the double quotes space '''grepdemo.txt'''
  
 
|-
 
|-
 
|04:28
 
|04:28
|And Press '''Enter.'''
+
|and press '''Enter.'''
  
 
|-
 
|-
Line 232: Line 224:
 
|-
 
|-
 
|04:37
 
|04:37
|If we want to see the line number in the file at which the enlisted entries are, we have the '''minus n''' option
+
|If we want to see the line number in the file at which the enlisted entries are, we have the '''minus n''' option.
  
 
|-
 
|-
Line 240: Line 232:
 
|-
 
|-
 
|04:49
 
|04:49
|  Now type "'''grep space -in space within double quote "fail" after the double quotes space grepdemo.txt'''
+
|  Now, type: '''grep space -in space within double quote "fail" after the double quotes space grepdemo.txt'''
  
 
|-
 
|-
Line 256: Line 248:
 
|-
 
|-
 
|05:10
 
|05:10
|We may have multiword patterns as well.  
+
|We may have multi-word patterns as well.  
  
 
|-
 
|-
 
|05:13
 
|05:13
|But the entire pattern must be within '''quotes'''.
+
|But the entire pattern must be within quotes.
  
 
|-
 
|-
 
|05:17
 
|05:17
|So type: '''grep space minus i space'''within double quotes '''ankit space saraf after the double quotes space grepdemo.txt '''
+
|So, type: '''grep space minus i space''' within double quotes '''ankit space saraf after the double quotes space grepdemo.txt'''
  
 
|-
 
|-
Line 272: Line 264:
 
|-
 
|-
 
|05:31
 
|05:31
|We see that '''Ankit Saraf''''s record is displayed.
+
|We see that Ankit Saraf's record is displayed.
  
 
|-
 
|-
Line 280: Line 272:
 
|-
 
|-
 
|05:39
 
|05:39
|For this Type:
+
|For this, type:
'''grep space minus i space''' within double quotes '''fail after double quotes space grepdemo.txt space notpass.txt'''  
+
'''grep space minus i space''' within double quotes '''fail''' after double quotes '''space grepdemo.txt space notpass.txt'''  
  
 
|-
 
|-
 
|05:55
 
|05:55
|'''Press Enter'''.
+
|Press '''Enter'''.
  
 
|-
 
|-
 
|05:57
 
|05:57
|The output is displayed.
+
|The '''output''' is displayed.
  
 
|-
 
|-
 
|05:59
 
|05:59
|With multiple files, '''grep''' will write the name of the file in which the entry was found.'''grepdemo.txt''' and '''notpass.txt'''
+
|With multiple files, '''grep''' will write the name of the file in which the entry was found. '''grepdemo.txt''' and '''notpass.txt'''.
  
 
|-
 
|-
Line 301: Line 293:
 
|-
 
|-
 
|06:18
 
|06:18
|Suppose we may only want to know the '''number of matches '''or '''count''' .
+
|Suppose, we may only want to know the number of matches or '''count''' .
  
 
|-
 
|-
 
|06:23
 
|06:23
|For that, we have the '''minus c''' option
+
|For that, we have the '''minus c''' option.
  
 
|-
 
|-
 
|06:27
 
|06:27
| So Type: '''grep space minus c space'''within double quotes '''Fail  with a capital F after the quotes space grepdemo.txt'''
+
| So, type: '''grep space minus c space''' within double quotes '''Fail''' with a capital F after the quotes '''space grepdemo.txt'''
  
 
|-
 
|-
Line 317: Line 309:
 
|-
 
|-
 
|06:42
 
|06:42
|This will give us the '''count''' of number of lines matched.
+
|This will give us the count of number of lines matched.
  
 
|-
 
|-
Line 329: Line 321:
 
|-
 
|-
 
| 06:53
 
| 06:53
| In this tutorial we learnt,
+
| In this tutorial, we learnt:
  
 
|-
 
|-
 
|06:55
 
|06:55
|*To see the content of a file
+
|To see the content of a file e.g. '''cat filename'''
**eg. '''cat filename'''
+
 
|-
 
|-
 
|06:59
 
|06:59
|*To list the entries of a particular stream
+
| To list the entries of a particular stream e.g. '''grep “computers” grepdemo.txt'''
**eg. '''grep “computers” grepdemo.txt'''
+
  
 
|-
 
|-
 
|07:06
 
|07:06
|*To ignore cases
+
|To ignore cases e.g. '''grep -i “computers” grepdemo.txt'''
**eg. '''grep -i “computers” grepdemo.txt'''
+
  
 
|-
 
|-
 
|07:14
 
|07:14
|*Lines that do not match the pattern
+
|Lines that do not match the pattern e.g. '''grep -iv “pass” grepdemo.txt'''
**eg. '''grep -iv “pass” grepdemo.txt'''
+
  
 
|-
 
|-
 
|07:22
 
|07:22
|*To list the line numbers with the entries
+
|To list the line numbers with the entries e.g.''' grep -in “fail” grepdemo.txt'''
**eg.''' grep -in “fail” grepdemo.txt'''
+
  
 
|-
 
|-
 
|07:31
 
|07:31
|*To store the result in another file
+
|To store the result in another file e.g. '''grep -iv “pass” grepdemo.txt notpass.txt''' and
**eg. '''grep -iv “pass” grepdemo.txt > notpass.txt'''
+
  
 
|-
 
|-
 
|07:41
 
|07:41
|And*To know the count
+
|To know the count e.g.''' grep -c “Fail” grepdemo.txt'''.
**eg.''' grep -c “Fail” grepdemo.txt'''
+
  
 
|-
 
|-
Line 371: Line 356:
 
|-
 
|-
 
|07:50
 
|07:50
|Explore some other commands like '''-E, + and ?'''
+
|explore some other commands like '''-E, + and ?'''.
  
 
|-
 
|-
Line 379: Line 364:
 
|-
 
|-
 
|07:58
 
|07:58
|It summarises the Spoken Tutorial project.
+
|It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
Line 387: Line 372:
 
|-
 
|-
 
|08:05
 
|08:05
|The Spoken Tutorial Project Team
+
|The Spoken Tutorial Project Team:
  
 
|-
 
|-
 
|08:07
 
|08:07
|*Conducts workshops using spoken tutorials
+
|Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
|08:11
 
|08:11
|*Gives certificates to those who pass an online test
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
 
|08:14
 
|08:14
|For more details, please write to
+
|For more details, please write to'''contact@spoken-tutorial.org'''
'''contact@spoken-tutorial.org'''
+
  
 
|-
 
|-
 
|08:21
 
|08:21
|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.
  
 
|-
 
|-
 
|08:25
 
|08:25
|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:32
 
|08:32
|More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro
+
|More information on this mission is available at: http://spoken-tutorial.org\NMEICT-Intro
  
 
|-
 
|-
 
|08:36
 
|08:36
|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 16:22, 7 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on grep command.
00:05 In this tutorial, we will learn grep command.
00:09 We will do this with the help of some examples.
00:12 To record this tutorial, I am using:
00:15 Linux Operating System and
00:18 GNU BASH version 4.2.24
00:22 Please note, GNU bash version 4 or above is recommended to practice this tutorial.
00:30 As prerequisites, you should know basics of Linux terminal.
00:34 For relevant tutorials, please visit our website which is as shown.
00:39 First, let us know about regular expressions .
00:43 * Regular expressions are pattern matching techniques.
00:47 * when we have to find out whether a pattern exists in a line, paragraph or a file.
00:54 For ex. If you want to search a phone number in the telephone directory
01:01 or to find a keyword in a paragraph or a line, we use grep command.

Let us move on to grep.

01:08 grep searches for one or more patterns in one or more lines, paragraph or a file.
01:15 If file-name is not mentioned, grep searches for the patterns in the standard input.
01:22 If filename is missing, grep searches for the patterns in the standard input.
01:28 I will demonstrate usage of grep using a demo file called grepdemo.txt.
01:35 Let us see the content of the file.
01:37 This is a file that has 13 entries.
01:41 Each entry has 6 fields- roll number, name, stream, marks and stipend amount.
01:50 The fields are separated by a bar which is called a delimiter.
01:55 Let us see how grep works.
01:58 Say, we want to use 'grep' command to see who are the students in the computers stream.
02:04 For this, we have to open the terminal.
02:07 Now, type on the terminal:
02:09 grep space (within double quotes) computers after the double quotes space grepdemo .txt
02:18 Press Enter.
02:20 This would enlist those entries where stream is computers.
02:25 Now, compare the result with the original file.
02:29 Come back to our text editor.
02:31 We see that the entry for Zubin is not enlisted.
02:37 Why this is so?
02:38 This is because grep searched for the pattern “computers” with small c
02:43 while for Zubin, the stream is “Computers” with a capital C.
02:48 The pattern matching is case sensitive.
02:51 To make it case insensitive, we need to use the minus i option with grep.
02:58 Come back to our terminal. Now, type:

grep space minus i space within double quotes computers after the double quotes space grepdemo.txt

03:12 Press Enter.This will now enlist all the four entries.
03:17 So we saw, grep enlists only those lines of files that match a given pattern.
03:23 We may do the reverse.
03:26 It is possible to make grep enlist only those lines that do not match the pattern.
03:32 For that, we have the minus v option.
03:35 Say, we want to enlist those entries of students who have not passed.
03:40 We can also store this result in another file.
03:43 For this, type:

grep space minus iv space within double quotes pass after the double quotes space grepdemo.txt space greater than sign space notpass.txt

04:02 Press Enter.
04:04 To see the content of the file, type: cat space notpass.txt .
04:11 Press Enter.The output is displayed.
04:15 Now, at the prompt, type:
04:17 grep space minus i space within double quotes fail after the double quotes space grepdemo.txt
04:28 and press Enter.
04:30 This is different.
04:32 This will include those students who are failed but their result is incomplete.
04:37 If we want to see the line number in the file at which the enlisted entries are, we have the minus n option.
04:46 Let us clear the prompt.
04:49 Now, type: grep space -in space within double quote "fail" after the double quotes space grepdemo.txt
05:01 Press Enter.
05:03 The line number is displayed.
05:06 The patterns so far have been of single word.
05:10 We may have multi-word patterns as well.
05:13 But the entire pattern must be within quotes.
05:17 So, type: grep space minus i space within double quotes ankit space saraf after the double quotes space grepdemo.txt
05:29 Press Enter.
05:31 We see that Ankit Saraf's record is displayed.
05:35 We can also find patterns in multiple files.
05:39 For this, type:

grep space minus i space within double quotes fail after double quotes space grepdemo.txt space notpass.txt

05:55 Press Enter.
05:57 The output is displayed.
05:59 With multiple files, grep will write the name of the file in which the entry was found. grepdemo.txt and notpass.txt.
06:10 These are the records from notpass.txt file and these are the records from grepdemo.txt file.
06:18 Suppose, we may only want to know the number of matches or count .
06:23 For that, we have the minus c option.
06:27 So, type: grep space minus c space within double quotes Fail with a capital F after the quotes space grepdemo.txt
06:40 Press Enter.
06:42 This will give us the count of number of lines matched.
06:46 This brings us to the end of this tutorial.
06:51 Let us summarize.
06:53 In this tutorial, we learnt:
06:55 To see the content of a file e.g. cat filename
06:59 To list the entries of a particular stream e.g. grep “computers” grepdemo.txt
07:06 To ignore cases e.g. grep -i “computers” grepdemo.txt
07:14 Lines that do not match the pattern e.g. grep -iv “pass” grepdemo.txt
07:22 To list the line numbers with the entries e.g. grep -in “fail” grepdemo.txt
07:31 To store the result in another file e.g. grep -iv “pass” grepdemo.txt notpass.txt and
07:41 To know the count e.g. grep -c “Fail” grepdemo.txt.
07:48 As an assignment,
07:50 explore some other commands like -E, + and ?.
07:56 Watch the video available at the link shown below.
07:58 It summarizes the Spoken Tutorial project.
08:01 If you do not have good bandwidth, you can download and watch it.
08:05 The Spoken Tutorial Project Team:
08:07 Conducts workshops using spoken tutorials.
08:11 Gives certificates to those who pass an online test.
08:14 For more details, please write tocontact@spoken-tutorial.org
08:21 Spoken Tutorial project is a part of the Talk to a Teacher project.
08:25 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
08:32 More information on this mission is available at: http://spoken-tutorial.org\NMEICT-Intro
08:36 This is Ashwini Patil from IIT Bombay, signing off. Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14