Difference between revisions of "BOSS-Linux/C3/The-grep-command/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) (Created page with "{|border=1 |'''Time''' |'''Narration''' |- |00:01 |Welcome to the spoken tutorial on '''grep''' command |- |00:05 |In this tutorial we will learn '''grep command'''. |- |...") |
PoojaMoolya (Talk | contribs) |
||
Line 16: | Line 16: | ||
|- | |- | ||
− | |00: | + | |00:11 |
|To record this tutorial, I am using | |To record this tutorial, I am using | ||
|- | |- | ||
|00:15 | |00:15 | ||
− | |*''' Linux''' ''' Operating System''' | + | |*'''Ubuntu Linux''' 12.04''' Operating System''' |
|- | |- | ||
− | |00: | + | |00:20 |
| and *'''GNU BASH''' version 4.2.24 | | and *'''GNU BASH''' version 4.2.24 | ||
|- | |- | ||
− | |00: | + | |00:24 |
− | |Please note,''' GNU bash''' version 4 or above is recommended to | + | |Please note,''' GNU bash''' version 4 or above is recommended to practice this tutorial. |
|- | |- | ||
− | |00: | + | |00:32 |
− | |As | + | |As prerequisitesYou should know basics of '''Linux terminal''' |
|- | |- | ||
− | |00: | + | |00:36 |
|For relevant tutorials, please visit our website which is as shown. | |For relevant tutorials, please visit our website which is as shown. | ||
|- | |- | ||
− | |00: | + | |00:41 |
|First let us know about regular expressions. | |First let us know about regular expressions. | ||
|- | |- | ||
− | |00: | + | |00:45 |
|*Regular expressions are pattern matching techniques. | |*Regular expressions are pattern matching techniques. | ||
|- | |- | ||
− | |00: | + | |00:50 |
|*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 exist in a line, paragraph or a file. | ||
|- | |- | ||
− | |00: | + | |00:56 |
|For ex. If you want to search a phone number in the telephone directory | |For ex. If you want to search a phone number in the telephone directory | ||
|- | |- | ||
− | | 01: | + | | 01:02 |
| 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: | + | |01:11 |
|'''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 line, paragraph or a file. | ||
|- | |- | ||
− | |01: | + | |01:17 |
|If filename is not mentioned,''' grep''' search for the patterns in the standard input. | |If filename is not mentioned,''' grep''' search for the patterns in the standard input. | ||
|- | |- | ||
− | |01: | + | |01:23 |
|If filename is missing, '''grep''' searches for the patterns in the standard input. | |If filename is missing, '''grep''' searches for the patterns in the standard input. | ||
|- | |- | ||
− | |01: | + | |01:30 |
|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''' | ||
|- | |- | ||
− | |01: | + | |01:37 |
|Let us see the content of the file. | |Let us see the content of the file. | ||
|- | |- | ||
− | |01: | + | |01:40 |
|This is a file that has 13 entries. | |This is a file that has 13 entries. | ||
|- | |- | ||
− | |01: | + | |01:44 |
|Each entry has 6 fields roll number, name, stream, marks, and stipend amount. | |Each entry has 6 fields roll number, name, stream, marks, and stipend amount. | ||
|- | |- | ||
− | |01: | + | |01:52 |
|The fields are separated by a bar, which is called a '''delimiter'''. | |The fields are separated by a bar, which is called a '''delimiter'''. | ||
|- | |- | ||
− | |01: | + | |01:56 |
|Let us see how '''grep''' works. | |Let us see how '''grep''' works. | ||
|- | |- | ||
− | | | + | |02:00 |
|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: | + | |02:07 |
|For this we have to open the '''terminal'''. | |For this we have to open the '''terminal'''. | ||
|- | |- | ||
− | |02: | + | |02:10 |
+ | |So press '''CTRL + ALT and T''' keys simultaneously on your keyboard. | ||
+ | |||
+ | |- | ||
+ | |02:16 | ||
|Now type on the '''terminal''': | |Now type on the '''terminal''': | ||
|- | |- | ||
− | |02: | + | |02:18 |
|'''grep space (within double quotes) computers after the double quotes space grepdemo .txt''' | |'''grep space (within double quotes) computers after the double quotes space grepdemo .txt''' | ||
|- | |- | ||
− | |02: | + | |02:27 |
|Press Enter | |Press Enter | ||
|- | |- | ||
− | |02: | + | |02:28 |
|This would enlist those entries where stream is '''computers'''. | |This would enlist those entries where stream is '''computers'''. | ||
|- | |- | ||
− | |02: | + | |02:33 |
|Now compare the result with the original file. | |Now compare the result with the original file. | ||
|- | |- | ||
− | |02: | + | |02:37 |
|Come back to our text editor. | |Come back to our text editor. | ||
|- | |- | ||
− | |02: | + | |02:40 |
|We see that the entry for ''' Zubin''' is not enlisted. | |We see that the entry for ''' Zubin''' is not enlisted. | ||
|- | |- | ||
− | |02: | + | |02:45 |
|Why this is so? | |Why this is so? | ||
|- | |- | ||
− | |02: | + | |02:46 |
|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: | + | |02:52 |
|While for '''Zubin''', the stream is “Computers” with a capital '''C'''. | |While for '''Zubin''', the stream is “Computers” with a capital '''C'''. | ||
|- | |- | ||
− | |02: | + | |02:57 |
|The pattern matching is '''case sensitive'''. | |The pattern matching is '''case sensitive'''. | ||
|- | |- | ||
− | | | + | |03:00 |
|To make it '''case''' insensitive, we need to use the '''minus i ''' option with '''grep'''. | |To make it '''case''' insensitive, we need to use the '''minus i ''' option with '''grep'''. | ||
|- | |- | ||
− | | | + | |03:06 |
− | | | + | |From 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: | + | |03:20 |
|Press ''' Enter.''' | |Press ''' Enter.''' | ||
|- | |- | ||
− | |03: | + | |03:21 |
|This will now enlist all the four entries. | |This will now enlist all the four entries. | ||
|- | |- | ||
− | |03: | + | |03:25 |
|So we saw, '''grep''' enlists only those lines of files that match a given pattern. | |So we saw, '''grep''' enlists only those lines of files that match a given pattern. | ||
|- | |- | ||
− | |03: | + | |03:32 |
|We may do the reverse. | |We may do the reverse. | ||
|- | |- | ||
− | |03: | + | |03:34 |
|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: | + | |03:40 |
|For that we have the '''minus v''' option. | |For that we have the '''minus v''' option. | ||
|- | |- | ||
− | |03: | + | |03:43 |
|Say, we want to enlist those entries of students who have not passed. | |Say, we want to enlist those entries of students who have not passed. | ||
|- | |- | ||
− | |03: | + | |03:48 |
|We can also store this result in another file | |We can also store this result in another file | ||
|- | |- | ||
− | |03: | + | |03:52 |
|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 ''' | ||
|- | |- | ||
− | |04: | + | |04:11 |
|Press '''Enter.''' | |Press '''Enter.''' | ||
|- | |- | ||
− | |04: | + | |04:12 |
|To see the content of file, type: '''cat space notpass.txt ''' | |To see the content of file, type: '''cat space notpass.txt ''' | ||
|- | |- | ||
− | |04: | + | |04:20 |
|Press '''Enter'''. | |Press '''Enter'''. | ||
|- | |- | ||
− | |04: | + | |04:21 |
|The output is displayed. | |The output is displayed. | ||
|- | |- | ||
− | |04: | + | |04:24 |
|Now at the '''prompt''' type: | |Now at the '''prompt''' type: | ||
|- | |- | ||
− | |04: | + | |04:26 |
|''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: | + | |04:37 |
|And Press '''Enter.''' | |And Press '''Enter.''' | ||
|- | |- | ||
− | |04: | + | |04:38 |
|This is different. | |This is different. | ||
|- | |- | ||
− | |04: | + | |04:41 |
|This will include those students who are failed but their result is incomplete. | |This will include those students who are failed but their result is incomplete. | ||
|- | |- | ||
− | |04: | + | |04:46 |
|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 | ||
|- | |- | ||
− | |04: | + | |04:54 |
|Let us clear the '''prompt'''. | |Let us clear the '''prompt'''. | ||
|- | |- | ||
− | |04: | + | |04:58 |
| 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''' | ||
|- | |- | ||
− | |05: | + | |05:09 |
|Press '''Enter'''. | |Press '''Enter'''. | ||
|- | |- | ||
− | |05: | + | |05:11 |
|The line number is displayed. | |The line number is displayed. | ||
|- | |- | ||
− | |05: | + | |05:15 |
|The patterns so far have been of single word. | |The patterns so far have been of single word. | ||
|- | |- | ||
− | |05: | + | |05:18 |
|We may have multiword patterns as well. | |We may have multiword patterns as well. | ||
|- | |- | ||
− | |05: | + | |05:21 |
|But the entire pattern must be within '''quotes'''. | |But the entire pattern must be within '''quotes'''. | ||
|- | |- | ||
− | |05: | + | |05:24 |
|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 ''' | ||
|- | |- | ||
− | |05: | + | |05:38 |
|Press '''Enter'''. | |Press '''Enter'''. | ||
|- | |- | ||
− | |05: | + | |05:40 |
|We see that '''Ankit Saraf''''s record is displayed. | |We see that '''Ankit Saraf''''s record is displayed. | ||
|- | |- | ||
− | |05: | + | |05:44 |
|We can also find patterns in multiple files. | |We can also find patterns in multiple files. | ||
|- | |- | ||
− | |05: | + | |05:48 |
|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''' | ||
|- | |- | ||
− | | | + | |06:03 |
|'''Press Enter'''. | |'''Press Enter'''. | ||
|- | |- | ||
− | | | + | |06:04 |
|The output is displayed. | |The output is displayed. | ||
|- | |- | ||
− | | | + | |06:07 |
|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''' | ||
|- | |- | ||
− | |06: | + | |06:18 |
|These are the records from '''notpass.txt''' file and these are the records from '''grepdemo.txt''' file. | |These are the records from '''notpass.txt''' file and these are the records from '''grepdemo.txt''' file. | ||
|- | |- | ||
− | |06: | + | |06:26 |
|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: | + | |06:31 |
|For that, we have the '''minus c''' option | |For that, we have the '''minus c''' option | ||
|- | |- | ||
− | |06: | + | |06:35 |
| 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''' | ||
|- | |- | ||
− | |06: | + | |06:48 |
|Press '''Enter'''. | |Press '''Enter'''. | ||
|- | |- | ||
− | |06: | + | |06:50 |
|This will give us the '''count''' of number of lines matched. | |This will give us the '''count''' of number of lines matched. | ||
|- | |- | ||
− | |06: | + | |06:55 |
|This brings us to the end of this tutorial. | |This brings us to the end of this tutorial. | ||
|- | |- | ||
− | |06: | + | |06:59 |
|Let us summarize. | |Let us summarize. | ||
|- | |- | ||
− | | | + | | 07:01 |
| In this tutorial we learnt, | | In this tutorial we learnt, | ||
|- | |- | ||
− | | | + | |07:03 |
|*To see the content of a file | |*To see the content of a file | ||
**eg. '''cat filename''' | **eg. '''cat filename''' | ||
|- | |- | ||
− | | | + | |07:07 |
|*To list the entries of a particular stream | |*To list the entries of a particular stream | ||
**eg. '''grep “computers” grepdemo.txt''' | **eg. '''grep “computers” grepdemo.txt''' | ||
|- | |- | ||
− | |07: | + | |07:14 |
|*To ignore cases | |*To ignore cases | ||
**eg. '''grep -i “computers” grepdemo.txt''' | **eg. '''grep -i “computers” grepdemo.txt''' | ||
|- | |- | ||
− | |07: | + | |07:21 |
|*Lines that do not match the pattern | |*Lines that do not match the pattern | ||
**eg. '''grep -iv “pass” grepdemo.txt''' | **eg. '''grep -iv “pass” grepdemo.txt''' | ||
|- | |- | ||
− | |07: | + | |07:30 |
|*To list the line numbers with the entries | |*To list the line numbers with the entries | ||
**eg.''' grep -in “fail” grepdemo.txt''' | **eg.''' grep -in “fail” grepdemo.txt''' | ||
|- | |- | ||
− | |07: | + | |07:38 |
|*To store the result in another file | |*To store the result in another file | ||
**eg. '''grep -iv “pass” grepdemo.txt > notpass.txt''' | **eg. '''grep -iv “pass” grepdemo.txt > notpass.txt''' | ||
|- | |- | ||
− | |07: | + | |07:50 |
|And*To know the count | |And*To know the count | ||
**eg.''' grep -c “Fail” grepdemo.txt''' | **eg.''' grep -c “Fail” grepdemo.txt''' | ||
|- | |- | ||
− | |07: | + | |07:57 |
|As an assignment, | |As an assignment, | ||
|- | |- | ||
− | |07: | + | |07:58 |
|Explore some other commands like '''-E, + and ?''' | |Explore some other commands like '''-E, + and ?''' | ||
|- | |- | ||
− | | | + | |08:04 |
|Watch the video available at the link shown below. | |Watch the video available at the link shown below. | ||
|- | |- | ||
− | | | + | |08:06 |
|It summarises the Spoken Tutorial project. | |It summarises the Spoken Tutorial project. | ||
|- | |- | ||
− | |08: | + | |08:10 |
|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. | ||
|- | |- | ||
− | |08: | + | |08:14 |
|The Spoken Tutorial Project Team | |The Spoken Tutorial Project Team | ||
|- | |- | ||
− | |08: | + | |08:16 |
|*Conducts workshops using spoken tutorials | |*Conducts workshops using spoken tutorials | ||
|- | |- | ||
− | |08: | + | |08:19 |
|*Gives certificates to those who pass an online test | |*Gives certificates to those who pass an online test | ||
|- | |- | ||
− | |08: | + | |08:23 |
|For more details, please write to | |For more details, please write to | ||
'''contact@spoken-tutorial.org''' | '''contact@spoken-tutorial.org''' | ||
|- | |- | ||
− | |08: | + | |08:30 |
|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: | + | |08:33 |
|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: | + | |08:40 |
|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: | + | |08:45 |
|This is Ashwini Patil from IIT Bombay signning off. Thank you for joining. | |This is Ashwini Patil from IIT Bombay signning off. Thank you for joining. | ||
|} | |} |
Revision as of 13:00, 12 February 2015
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:11 | To record this tutorial, I am using |
00:15 | *Ubuntu Linux 12.04 Operating System |
00:20 | and *GNU BASH version 4.2.24 |
00:24 | Please note, GNU bash version 4 or above is recommended to practice this tutorial. |
00:32 | As prerequisitesYou should know basics of Linux terminal |
00:36 | For relevant tutorials, please visit our website which is as shown. |
00:41 | First let us know about regular expressions. |
00:45 | *Regular expressions are pattern matching techniques. |
00:50 | *When we have to find out whether a pattern exist in a line, paragraph or a file. |
00:56 | For ex. If you want to search a phone number in the telephone directory |
01:02 | Or To find a keyword in a paragraph or a line, we use grep command
Let us move on to grep. |
01:11 | grep searches for one or more patterns in one or more line, paragraph or a file. |
01:17 | If filename is not mentioned, grep search for the patterns in the standard input. |
01:23 | If filename is missing, grep searches for the patterns in the standard input. |
01:30 | I will demonstrate usage of grep using a demo file called grepdemo.txt |
01:37 | Let us see the content of the file. |
01:40 | This is a file that has 13 entries. |
01:44 | Each entry has 6 fields roll number, name, stream, marks, and stipend amount. |
01:52 | The fields are separated by a bar, which is called a delimiter. |
01:56 | Let us see how grep works. |
02:00 | Say we want to use grep command, to see who are the students in the computers stream. |
02:07 | For this we have to open the terminal. |
02:10 | So press CTRL + ALT and T keys simultaneously on your keyboard. |
02:16 | Now type on the terminal: |
02:18 | grep space (within double quotes) computers after the double quotes space grepdemo .txt |
02:27 | Press Enter |
02:28 | This would enlist those entries where stream is computers. |
02:33 | Now compare the result with the original file. |
02:37 | Come back to our text editor. |
02:40 | We see that the entry for Zubin is not enlisted. |
02:45 | Why this is so? |
02:46 | This is because grep searched for the pattern “computers” with small c |
02:52 | While for Zubin, the stream is “Computers” with a capital C. |
02:57 | The pattern matching is case sensitive. |
03:00 | To make it case insensitive, we need to use the minus i option with grep. |
03:06 | From back to our terminal Now Type:
grep space (minus) i space (within double quotes) “computers” after the double quotes space grepdemo.txt |
03:20 | Press Enter. |
03:21 | This will now enlist all the four entries. |
03:25 | So we saw, grep enlists only those lines of files that match a given pattern. |
03:32 | We may do the reverse. |
03:34 | It is possible to make grep enlist only those lines that do not match the pattern. |
03:40 | For that we have the minus v option. |
03:43 | Say, we want to enlist those entries of students who have not passed. |
03:48 | We can also store this result in another file |
03:52 | 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:11 | Press Enter. |
04:12 | To see the content of file, type: cat space notpass.txt |
04:20 | Press Enter. |
04:21 | The output is displayed. |
04:24 | Now at the prompt type: |
04:26 | grep space minus i space' within double quotes fail after the double quotes space grepdemo.txt |
04:37 | And Press Enter. |
04:38 | This is different. |
04:41 | This will include those students who are failed but their result is incomplete. |
04:46 | If we want to see the line number in the file at which the enlisted entries are, we have the minus n option |
04:54 | Let us clear the prompt. |
04:58 | Now type "grep space -in space within double quote "fail" after the double quotes space grepdemo.txt |
05:09 | Press Enter. |
05:11 | The line number is displayed. |
05:15 | The patterns so far have been of single word. |
05:18 | We may have multiword patterns as well. |
05:21 | But the entire pattern must be within quotes. |
05:24 | So type: grep space minus i spacewithin double quotes ankit space saraf after the double quotes space grepdemo.txt |
05:38 | Press Enter. |
05:40 | We see that Ankit Saraf's record is displayed. |
05:44 | We can also find patterns in multiple files. |
05:48 | For this Type:
grep space minus i space within double quotes fail after double quotes space grepdemo.txt space notpass.txt |
06:03 | Press Enter. |
06:04 | The output is displayed. |
06:07 | With multiple files, grep will write the name of the file in which the entry was found.grepdemo.txt and notpass.txt |
06:18 | These are the records from notpass.txt file and these are the records from grepdemo.txt file. |
06:26 | Suppose we may only want to know the number of matches or count . |
06:31 | For that, we have the minus c option |
06:35 | So Type: grep space minus c spacewithin double quotes Fail with a capital F after the quotes space grepdemo.txt |
06:48 | Press Enter. |
06:50 | This will give us the count of number of lines matched. |
06:55 | This brings us to the end of this tutorial. |
06:59 | Let us summarize. |
07:01 | In this tutorial we learnt, |
07:03 | *To see the content of a file
|
07:07 | *To list the entries of a particular stream
|
07:14 | *To ignore cases
|
07:21 | *Lines that do not match the pattern
|
07:30 | *To list the line numbers with the entries
|
07:38 | *To store the result in another file
|
07:50 | And*To know the count
|
07:57 | As an assignment, |
07:58 | Explore some other commands like -E, + and ? |
08:04 | Watch the video available at the link shown below. |
08:06 | It summarises the Spoken Tutorial project. |
08:10 | If you do not have good bandwidth, you can download and watch it. |
08:14 | The Spoken Tutorial Project Team |
08:16 | *Conducts workshops using spoken tutorials |
08:19 | *Gives certificates to those who pass an online test |
08:23 | For more details, please write to
contact@spoken-tutorial.org |
08:30 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
08:33 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
08:40 | More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
08:45 | This is Ashwini Patil from IIT Bombay signning off. Thank you for joining. |