Difference between revisions of "BOSS-Linux/C3/More-on-sed-command/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
PoojaMoolya (Talk | contribs) |
||
Line 18: | Line 18: | ||
|- | |- | ||
| 00:15 | | 00:15 | ||
− | | *''' | + | | *'''Linux''' ''' Operating System''' and |
|- | |- | ||
Line 25: | Line 25: | ||
|- | |- | ||
− | | 00: | + | | 00:23 |
| Please note,''' GNU Bash''' version 4 or above is recommended to practice this tutorial. | | Please note,''' GNU Bash''' version 4 or above is recommended to practice this tutorial. | ||
|- | |- | ||
− | | 00: | + | | 00:30 |
| As prerequisites, | | As prerequisites, | ||
|- | |- | ||
− | | 00: | + | | 00:33 |
| You should know basics of '''Linux terminal.''' | | You should know basics of '''Linux terminal.''' | ||
|- | |- | ||
− | | 00: | + | | 00:36 |
− | | You should be aware of sed tool. | + | | You should be aware of '''sed''' tool. |
|- | |- | ||
− | | 00: | + | | 00:39 |
| For relevant tutorials please visit our website which as shown: http://spoken-tutorial.org | | For relevant tutorials please visit our website which as shown: http://spoken-tutorial.org | ||
|- | |- | ||
− | | 00: | + | | 00:45 |
| The major use of '''sed''' is substitution. | | The major use of '''sed''' is substitution. | ||
Line 53: | Line 53: | ||
|- | |- | ||
− | | 00: | + | | 00:54 |
| Let's first look at the original file '''seddemo.txt''' | | Let's first look at the original file '''seddemo.txt''' | ||
|- | |- | ||
− | | 01: | + | | 01:00 |
| Notice the word '''Kumar''' occurs two times in the fourth line and once in the sixth line. | | Notice the word '''Kumar''' occurs two times in the fourth line and once in the sixth line. | ||
Line 65: | Line 65: | ||
|- | |- | ||
− | | 01: | + | | 01:15 |
|Type on the '''terminal''' | |Type on the '''terminal''' | ||
|- | |- | ||
− | | 01: | + | | 01:17 |
| '''sed space''' within single quote ''''s front slash / opening square bracket small ''k'' capital ''K'' closing square bracket umar slash Roy slash'''' after the single quotes space '''seddemo.txt''' | | '''sed space''' within single quote ''''s front slash / opening square bracket small ''k'' capital ''K'' closing square bracket umar slash Roy slash'''' after the single quotes space '''seddemo.txt''' | ||
|- | |- | ||
− | | 01: | + | | 01:39 |
| Press '''Enter'''. | | Press '''Enter'''. | ||
|- | |- | ||
− | | 01: | + | | 01:42 |
| Notice the fourth line. | | Notice the fourth line. | ||
|- | |- | ||
− | | 01: | + | | 01:45 |
| Only the first occurrence of '''Kumar''' is changed to '''Roy''', not the second one. | | Only the first occurrence of '''Kumar''' is changed to '''Roy''', not the second one. | ||
|- | |- | ||
− | | 01: | + | | 01:51 |
| Sixth line had one occurrence of the word '''Kumar''' and this is replaced now. | | Sixth line had one occurrence of the word '''Kumar''' and this is replaced now. | ||
Line 93: | Line 93: | ||
|- | |- | ||
− | | 02: | + | | 02:02 |
| This is because, by default, the first matched entry of any line is substituted. | | This is because, by default, the first matched entry of any line is substituted. | ||
|- | |- | ||
− | | 02: | + | | 02:10 |
| To substitute all the matched entries we need to use the flag ''' g''' option. | | To substitute all the matched entries we need to use the flag ''' g''' option. | ||
Line 106: | Line 106: | ||
|- | |- | ||
| 02:20 | | 02:20 | ||
− | | Type: | + | | Type: '''sed space within single quotes 's front slash opening square bracket ''small k'' ''capital K'' closing square bracket umar slash Roy slash g'''' after the single quote space '''seddemo.txt''' Press '''Enter''' |
− | '''sed space within single quotes 's front slash opening square bracket ''small k'' ''capital K'' closing square bracket umar slash Roy slash g'''' after the single quote space '''seddemo.txt''' Press '''Enter''' | + | |
|- | |- | ||
Line 114: | Line 113: | ||
|- | |- | ||
− | | 02: | + | | 02:47 |
| We can make multiple substitutions in one go as well. | | We can make multiple substitutions in one go as well. | ||
|- | |- | ||
− | | 02: | + | | 02:52 |
| Say we want to replace the words '''electronics''' with the word '''electrical''' | | Say we want to replace the words '''electronics''' with the word '''electrical''' | ||
|- | |- | ||
− | | 02: | + | | 02:57 |
| And '''civil''' with '''metallurgy''' in the file '''seddemo.txt''' | | And '''civil''' with '''metallurgy''' in the file '''seddemo.txt''' | ||
Line 130: | Line 129: | ||
|- | |- | ||
− | | 03: | + | | 03:06 |
− | | Type: | + | | Type: '''sed space hyphen '''e''' space within single quotes 's' front slash electronics slash electrical slash g’ after the single quote space hyphen '''e''' space within single quotes ‘s front slash civil slash metallurgy slash g’''' after the single quotes space '''seddemo.txt''' |
− | '''sed space hyphen '''e''' space within single quotes | + | |
|- | |- | ||
− | | 03: | + | | 03:35 |
| And press '''Enter.''' | | And press '''Enter.''' | ||
|- | |- | ||
− | | 03: | + | | 03:38 |
| You can see that the words are replaced. | | You can see that the words are replaced. | ||
|- | |- | ||
− | | 03: | + | | 03:41 |
| Now we want to change the '''stream''' of '''Anirban '''from '''computers''' to '''mathematics.''' | | Now we want to change the '''stream''' of '''Anirban '''from '''computers''' to '''mathematics.''' | ||
Line 151: | Line 149: | ||
|- | |- | ||
− | | 03: | + | | 03:52 |
| '''sed space''' within single quotes ''''front slash Anirban slash s slash computers slash mathematics slash g' ''' after the single quotes space '''seddemo.txt''' | | '''sed space''' within single quotes ''''front slash Anirban slash s slash computers slash mathematics slash g' ''' after the single quotes space '''seddemo.txt''' | ||
Line 159: | Line 157: | ||
|- | |- | ||
− | | 04: | + | | 04:13 |
| We see that the '''stream''' is changed. | | We see that the '''stream''' is changed. | ||
Line 167: | Line 165: | ||
|- | |- | ||
− | | 04: | + | | 04:20 |
| First we write '''sed''' then in single quotes we write the pattern to be matched. | | First we write '''sed''' then in single quotes we write the pattern to be matched. | ||
|- | |- | ||
− | | 04: | + | | 04:27 |
| This is '''Anirban'''. | | This is '''Anirban'''. | ||
|- | |- | ||
− | | 04: | + | | 04:29 |
| Now after the slash comes the operation. | | Now after the slash comes the operation. | ||
|- | |- | ||
− | | 04: | + | | 04:33 |
| This is '''s''' that stands for substitution, as we have already seen. | | This is '''s''' that stands for substitution, as we have already seen. | ||
|- | |- | ||
− | | 04: | + | | 04:40 |
| Then we mention the pattern to be replaced which is '''computers'''. | | Then we mention the pattern to be replaced which is '''computers'''. | ||
|- | |- | ||
− | | 04: | + | | 04:46 |
| Then the new word that would be substituted, which is '''mathematics'''. | | Then the new word that would be substituted, which is '''mathematics'''. | ||
|- | |- | ||
− | | 04: | + | | 04:52 |
| We can also use '''sed''' to add or delete lines in the file. | | We can also use '''sed''' to add or delete lines in the file. | ||
|- | |- | ||
− | | | + | | 04:59 |
| Say we want to select those lines which do not have '''stream''' as '''electronics.''' | | Say we want to select those lines which do not have '''stream''' as '''electronics.''' | ||
|- | |- | ||
− | | 05: | + | | 05:05 |
| For that, we have the '''d '''flag. | | For that, we have the '''d '''flag. | ||
|- | |- | ||
− | | 05: | + | | 05:09 |
− | | Type: | + | | Type: '''sed space''' within single quotes '''front slash electronics slash d''' after the single quotes '''space seddemo.txt space greater than sign space nonelectronics.txt''' |
− | '''sed space''' within single quotes '''front slash electronics slash d''' after the single quotes '''space seddemo.txt space greater than sign space nonelectronics.txt''' | + | |
|- | |- | ||
− | | 05: | + | | 05:30 |
| Press '''Enter'''. | | Press '''Enter'''. | ||
|- | |- | ||
− | | 05: | + | | 05:32 |
| To see the contents, type: '''cat space nonelectronics.txt''' | | To see the contents, type: '''cat space nonelectronics.txt''' | ||
|- | |- | ||
− | | 05: | + | | 05:41 |
| Say, at the start of the file we want to add a line '''Student Information'''. | | Say, at the start of the file we want to add a line '''Student Information'''. | ||
Line 224: | Line 221: | ||
|- | |- | ||
− | | 05: | + | | 05:53 |
| We need to type: '''sed space''' in single quotes ''''1i space Student Information' after the quote seddemo.txt ''' | | We need to type: '''sed space''' in single quotes ''''1i space Student Information' after the quote seddemo.txt ''' | ||
|- | |- | ||
− | | 06: | + | | 06:09 |
| And press '''Enter.''' | | And press '''Enter.''' | ||
|- | |- | ||
− | | 06: | + | | 06:12 |
| You can see the output. | | You can see the output. | ||
|- | |- | ||
− | | 06: | + | | 06:14 |
| In fact, we can enter multiple lines like this. | | In fact, we can enter multiple lines like this. | ||
|- | |- | ||
− | | 06: | + | | 06:19 |
| Say, we want to add the two lines we would do it in a similar way. | | Say, we want to add the two lines we would do it in a similar way. | ||
|- | |- | ||
− | | 06: | + | | 06:25 |
| Along with '''Student Information''' we also want to add '''academics''' in the next year. | | Along with '''Student Information''' we also want to add '''academics''' in the next year. | ||
|- | |- | ||
| 06:33 | | 06:33 | ||
− | | So in that case we would write | + | | So in that case we would write '''sed space''' in single quotes '''1i space Student Information slash n 2013'''' after the quotes '''seddemo.txt''' |
− | '''sed space''' in single quotes '''1i space Student Information slash n 2013'''' after the quotes '''seddemo.txt''' | + | |
|- | |- | ||
− | | 06: | + | | 06:54 |
| Press '''Enter''' | | Press '''Enter''' | ||
|- | |- | ||
− | | 06: | + | | 06:56 |
| Notice '''slash n''' between the string ‘Information’ and ‘2013’. | | Notice '''slash n''' between the string ‘Information’ and ‘2013’. | ||
|- | |- | ||
− | | 07: | + | | 07:04 |
| '''slash n '''prints 2013 in the next line after ‘Student Information’ | | '''slash n '''prints 2013 in the next line after ‘Student Information’ | ||
|- | |- | ||
− | | 07: | + | | 07:10 |
| This brings me to the end of this tutorial. | | This brings me to the end of this tutorial. | ||
Line 273: | Line 269: | ||
|- | |- | ||
− | | 07: | + | | 07:16 |
| In this tutorial we learnt, | | In this tutorial we learnt, | ||
|- | |- | ||
− | | 07: | + | | 07:18 |
| Substitution | | Substitution | ||
|- | |- | ||
− | | 07: | + | | 07:19 |
| Replacement | | Replacement | ||
|- | |- | ||
− | | 07: | + | | 07:20 |
| And Insertion | | And Insertion | ||
|- | |- | ||
− | | 07: | + | | 07:23 |
| As an assignment, Use the same text file '''seddemo.txt''' | | As an assignment, Use the same text file '''seddemo.txt''' | ||
|- | |- | ||
− | | 07: | + | | 07:29 |
| And try to replace or substitute name '''Ankit''' with '''Ashish''' | | And try to replace or substitute name '''Ankit''' with '''Ashish''' | ||
Line 305: | Line 301: | ||
|- | |- | ||
− | | 07: | + | | 07:41 |
| 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: | + | | 07:46 |
| The Spoken Tutorial Project Team Conducts workshops using spoken tutorials | | The Spoken Tutorial Project Team Conducts workshops using spoken tutorials | ||
|- | |- | ||
− | | 07: | + | | 07:52 |
| Gives certificates to those who pass an online test | | Gives certificates to those who pass an online test | ||
|- | |- | ||
− | | 07: | + | | 07:56 |
| For more details, please write to contact@spoken-tutorial.org | | For more details, please write to contact@spoken-tutorial.org | ||
Line 325: | Line 321: | ||
|- | |- | ||
− | | 08: | + | | 08:07 |
| 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 | ||
Revision as of 13:06, 12 February 2015
Time | Narration |
00:01 | Welcome to the spoken tutorial on More on sed. |
00:06 | In this tutorial, we will learn some More on sed commands, through some examples. |
00:13 | To record this tutorial, I am using |
00:15 | *Linux Operating System and |
00:20 | *GNU BASH version 4.2.24 |
00:23 | Please note, GNU Bash version 4 or above is recommended to practice this tutorial. |
00:30 | As prerequisites, |
00:33 | You should know basics of Linux terminal. |
00:36 | You should be aware of sed tool. |
00:39 | For relevant tutorials please visit our website which as shown: http://spoken-tutorial.org |
00:45 | The major use of sed is substitution. |
00:49 | Replacing some pattern in the input with something else. |
00:54 | Let's first look at the original file seddemo.txt |
01:00 | Notice the word Kumar occurs two times in the fourth line and once in the sixth line. |
01:10 | If you want to replace all occurrences of ‘Kumar’ with ‘Roy’ |
01:15 | Type on the terminal |
01:17 | sed space within single quote 's front slash / opening square bracket small k capital K closing square bracket umar slash Roy slash' after the single quotes space seddemo.txt |
01:39 | Press Enter. |
01:42 | Notice the fourth line. |
01:45 | Only the first occurrence of Kumar is changed to Roy, not the second one. |
01:51 | Sixth line had one occurrence of the word Kumar and this is replaced now. |
01:57 | So, we see only the first entry of the lines has been changed. |
02:02 | This is because, by default, the first matched entry of any line is substituted. |
02:10 | To substitute all the matched entries we need to use the flag g option. |
02:17 | Let me clear the prompt. |
02:20 | Type: sed space within single quotes 's front slash opening square bracket small k capital K closing square bracket umar slash Roy slash g' after the single quote space seddemo.txt Press Enter |
02:43 | Now, both entries of the fourth line are replaced. |
02:47 | We can make multiple substitutions in one go as well. |
02:52 | Say we want to replace the words electronics with the word electrical |
02:57 | And civil with metallurgy in the file seddemo.txt |
03:04 | Let me clear the prompt |
03:06 | Type: sed space hyphen e space within single quotes 's' front slash electronics slash electrical slash g’ after the single quote space hyphen e space within single quotes ‘s front slash civil slash metallurgy slash g’ after the single quotes space seddemo.txt |
03:35 | And press Enter. |
03:38 | You can see that the words are replaced. |
03:41 | Now we want to change the stream of Anirban from computers to mathematics. |
03:49 | In such case we would need to type: |
03:52 | sed space within single quotes 'front slash Anirban slash s slash computers slash mathematics slash g' after the single quotes space seddemo.txt |
04:11 | Press Enter. |
04:13 | We see that the stream is changed. |
04:17 | Let us understand what this is. |
04:20 | First we write sed then in single quotes we write the pattern to be matched. |
04:27 | This is Anirban. |
04:29 | Now after the slash comes the operation. |
04:33 | This is s that stands for substitution, as we have already seen. |
04:40 | Then we mention the pattern to be replaced which is computers. |
04:46 | Then the new word that would be substituted, which is mathematics. |
04:52 | We can also use sed to add or delete lines in the file. |
04:59 | Say we want to select those lines which do not have stream as electronics. |
05:05 | For that, we have the d flag. |
05:09 | Type: sed space within single quotes front slash electronics slash d after the single quotes space seddemo.txt space greater than sign space nonelectronics.txt |
05:30 | Press Enter. |
05:32 | To see the contents, type: cat space nonelectronics.txt |
05:41 | Say, at the start of the file we want to add a line Student Information. |
05:49 | For that we have the i action. |
05:53 | We need to type: sed space in single quotes '1i space Student Information' after the quote seddemo.txt |
06:09 | And press Enter. |
06:12 | You can see the output. |
06:14 | In fact, we can enter multiple lines like this. |
06:19 | Say, we want to add the two lines we would do it in a similar way. |
06:25 | Along with Student Information we also want to add academics in the next year. |
06:33 | So in that case we would write sed space in single quotes 1i space Student Information slash n 2013' after the quotes seddemo.txt |
06:54 | Press Enter |
06:56 | Notice slash n between the string ‘Information’ and ‘2013’. |
07:04 | slash n prints 2013 in the next line after ‘Student Information’ |
07:10 | This brings me to the end of this tutorial. |
07:14 | Let us summarize, |
07:16 | In this tutorial we learnt, |
07:18 | Substitution |
07:19 | Replacement |
07:20 | And Insertion |
07:23 | As an assignment, Use the same text file seddemo.txt |
07:29 | And try to replace or substitute name Ankit with Ashish |
07:35 | Watch the video available at the link shown below http://spoken-tutorial.org/What_is_a_Spoken Tutorial |
07:39 | It summarises the Spoken Tutorial project |
07:41 | If you do not have good bandwidth, you can download and watch it |
07:46 | The Spoken Tutorial Project Team Conducts workshops using spoken tutorials |
07:52 | Gives certificates to those who pass an online test |
07:56 | For more details, please write to contact@spoken-tutorial.org |
08:04 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
08:07 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
08:16 | More information on this Mission is available at the link shown below: http://spoken-tutorial.org\NMEICT-Intro |
08:22 | The script has been contributed by Anirban and Sachin. |
08:28 | This is Ashwini PAtil from IIT bombay signing off.
Thank you for joining. |