1 00:00:00,000 --> 00:00:01,270 [No audio] 2 00:00:01,270 --> 00:00:03,498 Hello everyone and welcome again to 3 00:00:03,524 --> 00:00:06,490 our newer lesson sed command. 4 00:00:06,670 --> 00:00:10,014 sed command is a substitute command which 5 00:00:10,052 --> 00:00:13,734 replaces or substitute a text with another 6 00:00:13,832 --> 00:00:17,110 text or manipulate your file. 7 00:00:17,230 --> 00:00:20,482 It is a very very powerful command. 8 00:00:20,626 --> 00:00:23,322 So what are the few things that sed command does? 9 00:00:23,456 --> 00:00:26,878 It replaces a string in a file with another string. 10 00:00:26,914 --> 00:00:30,654 So a string is a word, a sentence, text 11 00:00:30,692 --> 00:00:34,434 message or any kind of text message inside of 12 00:00:34,472 --> 00:00:37,350 your file that you want to replace. 13 00:00:37,910 --> 00:00:40,506 It finds and deletes a line. 14 00:00:40,628 --> 00:00:44,542 So if a line has ABC and you want to get rid 15 00:00:44,566 --> 00:00:49,002 of that line in that text file, well you could go in 16 00:00:49,196 --> 00:00:55,174 and use the sed command and delete that line that contains ABC. 17 00:00:55,282 --> 00:00:59,178 Now wait a second Imran hey, why can't I do the same thing 18 00:00:59,264 --> 00:01:02,634 when I go to vi and find the line and delete it? 19 00:01:02,672 --> 00:01:04,361 Yes, you could definitely do that. 20 00:01:04,436 --> 00:01:08,422 But what if you have a file that has let's 21 00:01:08,446 --> 00:01:12,198 say a million lines, and in those million lines you 22 00:01:12,224 --> 00:01:15,442 probably have at least 1000 lines that has ABC. 23 00:01:15,586 --> 00:01:18,886 Now are you going to go into the file 24 00:01:19,018 --> 00:01:23,166 and delete or replace that string one by one? 25 00:01:23,288 --> 00:01:26,370 You think that is efficient? Not at all. 26 00:01:26,420 --> 00:01:30,022 So that's why sed command is so powerful. 27 00:01:30,106 --> 00:01:34,594 That allows us to manipulate the text inside a file. 28 00:01:34,762 --> 00:01:37,218 Another example that we'll learn is how 29 00:01:37,244 --> 00:01:40,174 to remove empty lines from our file. 30 00:01:40,222 --> 00:01:42,478 If there are more than one empty lines, 31 00:01:42,514 --> 00:01:43,962 how can you get rid of it? 32 00:01:44,036 --> 00:01:46,698 Yes, of course, going back to the same thing that you 33 00:01:46,724 --> 00:01:49,242 could go into the vi and dd and remove it. 34 00:01:49,316 --> 00:01:51,450 But again, this is not productive. 35 00:01:51,950 --> 00:01:54,358 Remove the first line or number of lines 36 00:01:54,394 --> 00:01:57,706 in a file, to replace tabs with spaces. 37 00:01:57,838 --> 00:02:02,358 These are the very few examples of sed commands that 38 00:02:02,384 --> 00:02:07,558 I'm going to go over and substitute within vi editor. 39 00:02:07,594 --> 00:02:09,618 So if you are already in vi, and you 40 00:02:09,644 --> 00:02:14,838 wanted to replace a text xyz or text or 41 00:02:14,924 --> 00:02:19,014 anything with another text or another word, you could 42 00:02:19,052 --> 00:02:22,534 also do by going straight into the vi. 43 00:02:22,702 --> 00:02:26,478 But again, am I negating my 44 00:02:26,504 --> 00:02:27,954 statement, what I said before? 45 00:02:28,112 --> 00:02:30,526 No, because when you are going to the vi 46 00:02:30,598 --> 00:02:33,882 and you look for one word and then you 47 00:02:33,896 --> 00:02:36,030 replace it, again it's a manual process. 48 00:02:36,140 --> 00:02:38,118 But there is another way in vi that 49 00:02:38,144 --> 00:02:40,422 you could just find that text one time 50 00:02:40,496 --> 00:02:43,470 and it replaces it everywhere in one shot. 51 00:02:43,790 --> 00:02:51,406 And if there is so much more and more, that sed command 52 00:02:51,598 --> 00:02:55,174 has to offer. So I'm going to log into my Linux machine, 53 00:02:55,222 --> 00:02:58,746 I'm going to log in as a PuTTY client and I will 54 00:02:58,808 --> 00:03:04,640 show you a few examples of how sed command works. 55 00:03:05,750 --> 00:03:07,338 I'm logged in as myself. 56 00:03:07,484 --> 00:03:09,630 I am in my home directory. 57 00:03:10,370 --> 00:03:13,950 I have a file in my home directory, 58 00:03:14,968 --> 00:03:17,710 that is called, let's do ls -ltr here, 59 00:03:17,760 --> 00:03:19,982 that is called seinfeld-characters. 60 00:03:20,126 --> 00:03:24,130 So if you do cat on seinfeld-characters, 61 00:03:24,990 --> 00:03:28,990 you'll see all these characters of Seinfeld. 62 00:03:30,030 --> 00:03:31,858 Again, it's just a list of all 63 00:03:31,884 --> 00:03:34,226 the characters that played in Seinfeld. 64 00:03:34,358 --> 00:03:36,718 If you do not have that file or if you 65 00:03:36,744 --> 00:03:40,906 did not create that file previously, then go ahead and 66 00:03:41,028 --> 00:03:44,050 you could just pause it right here and create that 67 00:03:44,100 --> 00:03:45,982 file with all those names that I have. 68 00:03:46,056 --> 00:03:47,218 Or if you want to use a 69 00:03:47,244 --> 00:03:49,954 different file, different names, that's fine. 70 00:03:49,992 --> 00:03:51,286 It's just the example that I'm going to 71 00:03:51,288 --> 00:03:54,658 be using to explain how sed command works. 72 00:03:54,804 --> 00:03:56,654 So I already have this file. 73 00:03:56,762 --> 00:03:58,474 Now, the first thing I wanted to do, 74 00:03:58,512 --> 00:04:01,690 let's say, what if I wanted to replace 75 00:04:02,010 --> 00:04:03,910 one of the word with a different word? 76 00:04:03,960 --> 00:04:06,370 Let's say I wanted to replace Kenny. 77 00:04:06,690 --> 00:04:09,494 There's a character named Kenny Bania. 78 00:04:09,602 --> 00:04:11,234 How about if I wanted to replace 79 00:04:11,282 --> 00:04:13,570 his name from Kenny to Lenny? 80 00:04:14,610 --> 00:04:21,197 You would use the command sed, single quote s for substitute, 81 00:04:22,197 --> 00:04:28,171 Kenny with Lenny, so slash Lenny, 82 00:04:28,171 --> 00:04:30,277 and slash again, 83 00:04:30,430 --> 00:04:32,630 and if there are more than one 84 00:04:32,680 --> 00:04:34,802 Kenny, then you could type g, 85 00:04:34,936 --> 00:04:37,494 because this g stands for global. 86 00:04:37,542 --> 00:04:40,014 It will replace the entire file 87 00:04:40,062 --> 00:04:43,146 wherever you have the word Kenny. 88 00:04:43,278 --> 00:04:46,322 So by default, I always use g. 89 00:04:46,516 --> 00:04:48,614 You should also get into the habit of 90 00:04:48,652 --> 00:04:50,706 g if you want to replace it everywhere. 91 00:04:50,898 --> 00:04:56,210 So you close the single quote, and then 92 00:04:56,260 --> 00:04:58,430 you type the name of the file where 93 00:04:58,480 --> 00:05:01,122 you are trying to replace the word Kenny. 94 00:05:01,266 --> 00:05:02,246 Hit enter. 95 00:05:02,428 --> 00:05:04,838 And now you will see, at the 96 00:05:04,864 --> 00:05:08,298 bottom, it is replaced with Lenny. 97 00:05:08,454 --> 00:05:13,046 Now, another thing I do want to mention that this 98 00:05:13,108 --> 00:05:17,414 is going to display the change only on the screen. 99 00:05:17,512 --> 00:05:21,246 It is not actually going to make a change in the file. 100 00:05:21,378 --> 00:05:24,218 So if you cat out the file, you 101 00:05:24,244 --> 00:05:28,814 will see the name Kenny still there. 102 00:05:28,912 --> 00:05:31,374 But didn't we just replace it with Lenny? 103 00:05:31,542 --> 00:05:33,520 Yes, we did, but it did not 104 00:05:34,150 --> 00:05:37,230 make the change inside the file. 105 00:05:37,350 --> 00:05:41,126 It only makes the change to the screen. 106 00:05:41,248 --> 00:05:44,054 And if you want to have that output to 107 00:05:44,092 --> 00:05:46,190 another file, you could do that and that change 108 00:05:46,240 --> 00:05:48,162 will be reflected in the newer file. 109 00:05:48,246 --> 00:05:50,466 But if you want to make a change to the existing 110 00:05:50,538 --> 00:05:57,314 file, then what you have to do is, you come back 111 00:05:57,352 --> 00:06:00,074 to the same command by hitting up arrow key and you 112 00:06:00,112 --> 00:06:05,618 type -i, that is to insert the changes into the 113 00:06:05,644 --> 00:06:07,982 file, the same command, and you hit enter. 114 00:06:08,116 --> 00:06:12,498 Now, when you do cat seinfeld-characters, you'll 115 00:06:12,534 --> 00:06:16,770 see the name has changed to Lenny permanently. 116 00:06:16,890 --> 00:06:18,798 So this is how you replace Kenny 117 00:06:18,834 --> 00:06:20,778 with Lenny and save the file. 118 00:06:20,934 --> 00:06:22,082 Now, let's see, 119 00:06:22,156 --> 00:06:29,747 what if you want to replace the word Costanza. 120 00:06:29,747 --> 00:06:31,799 [No audio] 121 00:06:31,799 --> 00:06:33,626 So it works the same way. 122 00:06:33,688 --> 00:06:35,139 So you do sed 123 00:06:35,139 --> 00:06:41,228 [No audio] 124 00:06:41,228 --> 00:06:44,381 substitute Costanza, 125 00:06:44,381 --> 00:06:46,710 [No audio] 126 00:06:46,710 --> 00:06:49,426 and this time you just don't want to replace anything. 127 00:06:49,488 --> 00:06:50,974 You just want to remove that word. 128 00:06:51,049 --> 00:06:53,352 So you just put Costanza and 129 00:06:53,352 --> 00:06:55,282 don't put anything in there, 130 00:06:55,476 --> 00:06:59,258 g, and the name of the file characters. 131 00:06:59,294 --> 00:07:02,398 You see anyone who had the 132 00:07:02,424 --> 00:07:05,794 last name Costanza, that is gone. See right here. 133 00:07:05,832 --> 00:07:07,174 Frank Costanza is gone. 134 00:07:07,212 --> 00:07:08,722 Stell Castanza is gone. 135 00:07:08,856 --> 00:07:11,026 Another Costanza I have, the bottom is gone. 136 00:07:11,088 --> 00:07:12,550 George Costanza is gone. 137 00:07:12,660 --> 00:07:14,794 But again, this is gone only on the screen. 138 00:07:14,832 --> 00:07:16,378 And if you want to make a changes to the 139 00:07:16,404 --> 00:07:18,730 file, you have to use the -i option. 140 00:07:18,900 --> 00:07:21,634 I don't want to use the -i option this time 141 00:07:21,672 --> 00:07:25,426 because I wanted to show you how the sed works. 142 00:07:25,488 --> 00:07:27,540 So this way the file won't change. 143 00:07:28,710 --> 00:07:33,826 Let's just confirm our file has all the correct 144 00:07:33,888 --> 00:07:36,574 names that I want to have them in it. 145 00:07:36,612 --> 00:07:38,122 So it does have it. 146 00:07:38,256 --> 00:07:41,482 Next one I wanted to show you is how 147 00:07:41,616 --> 00:07:46,162 to find a string of line and remove it. 148 00:07:46,356 --> 00:07:49,522 If you see, this is the second 149 00:07:49,596 --> 00:07:53,474 one in our slide, find and delete. 150 00:07:53,582 --> 00:07:55,994 So what if I wanted to delete 151 00:07:56,102 --> 00:08:00,130 every line that has the word Seinfeld? 152 00:08:00,990 --> 00:08:04,193 So the command to do that is sed 153 00:08:04,193 --> 00:08:08,181 [No author] 154 00:08:08,181 --> 00:08:09,549 Seinfeld, 155 00:08:10,450 --> 00:08:12,652 and this time type d. 156 00:08:12,652 --> 00:08:15,805 [No audio] 157 00:08:15,805 --> 00:08:18,958 d is to delete any character 158 00:08:18,958 --> 00:08:22,366 or any word that comes up, that matches Seinfeld, 159 00:08:22,498 --> 00:08:24,214 that line will be deleted. 160 00:08:24,322 --> 00:08:27,630 So I am not using -i option because it will 161 00:08:27,680 --> 00:08:30,762 actually make the changes to my file and save it. 162 00:08:30,836 --> 00:08:31,782 I just want to show you. 163 00:08:31,796 --> 00:08:34,794 So I'll just run it and you will see 164 00:08:34,952 --> 00:08:39,642 all the lines that had the Seinfeld are gone. 165 00:08:39,716 --> 00:08:44,466 See, none of this has the word Seinfeld in it. 166 00:08:44,648 --> 00:08:47,501 So that's how you replace or delete a 167 00:08:47,515 --> 00:08:51,486 line that matches a keyword or a word. 168 00:08:51,668 --> 00:08:54,860 The next thing I wanted to show you is 169 00:08:55,490 --> 00:09:01,834 how you could remove empty lines from a file. 170 00:09:01,942 --> 00:09:05,094 So if I have empty lines, let's make the empty line. 171 00:09:05,132 --> 00:09:09,498 I'll go into seinfeld-characters and 172 00:09:09,524 --> 00:09:11,730 I'm going to make empty lines. 173 00:09:11,730 --> 00:09:14,670 [No audio] 174 00:09:14,670 --> 00:09:17,019 So I have four empty lines, right? 175 00:09:17,076 --> 00:09:20,822 I'll just make one empty line right here as well, five empty lines. 176 00:09:20,846 --> 00:09:22,481 Now I'm going to save that file, 177 00:09:22,481 --> 00:09:26,836 cat seinfeld-characters, 178 00:09:26,836 --> 00:09:34,828 [No audio]] 179 00:09:34,828 --> 00:09:38,482 and you will see right here I have, five empty lines. 180 00:09:38,482 --> 00:09:40,482 [No audio] 181 00:09:40,482 --> 00:09:42,550 five empty lines. 182 00:09:42,550 --> 00:09:45,598 I wanted to get rid of these five empty lines. 183 00:09:45,754 --> 00:09:48,005 The command to do that is sed, 184 00:09:48,005 --> 00:09:50,975 [No audio] 185 00:09:50,975 --> 00:09:52,160 slash, 186 00:09:52,160 --> 00:09:54,137 [No audio] 187 00:09:54,137 --> 00:09:57,504 cap, cap shows 188 00:09:57,504 --> 00:10:00,310 that anything that starts, which is right above number 189 00:10:00,360 --> 00:10:07,334 six and dollar, anything that ends with dollar meaning 190 00:10:07,382 --> 00:10:16,190 nothing, then just delete that, sorry, seinfeld-characters. 191 00:10:16,630 --> 00:10:19,538 So anything that is starting or anything that 192 00:10:19,564 --> 00:10:22,226 is ending has nothing in the middle, which 193 00:10:22,288 --> 00:10:24,422 is the empty file of course, right. 194 00:10:24,556 --> 00:10:27,362 So whatever that finds, please go ahead and delete it. 195 00:10:27,496 --> 00:10:29,846 So hit enter and you'll see everything is gone. 196 00:10:29,908 --> 00:10:32,558 But now if you do seinfeld-character again, 197 00:10:32,704 --> 00:10:34,550 you'll see it will still have the line. Why? 198 00:10:34,600 --> 00:10:38,042 Because we did not specify the -i option and I 199 00:10:38,056 --> 00:10:40,322 want you to go ahead and specify -i option. 200 00:10:40,456 --> 00:10:43,262 Do a seinfeld-character, and you'll see 201 00:10:43,336 --> 00:10:45,482 all the empty lines are gone. 202 00:10:45,676 --> 00:10:47,946 Now what if I wanted to remove 203 00:10:48,018 --> 00:10:50,826 the first line in a file? 204 00:10:51,018 --> 00:10:53,042 I just want to remove Jerry Seinfeld, which 205 00:10:53,056 --> 00:10:54,678 is the first line of the file. 206 00:10:54,714 --> 00:11:01,082 So I will do sed, quote, 1d, quote close, the name of 207 00:11:01,096 --> 00:11:05,658 the file, and you'll see the first line was Jerry Seinfeld. 208 00:11:05,754 --> 00:11:07,538 That is gone. Now 209 00:11:07,564 --> 00:11:11,282 of course, again, I keep saying it is not going to 210 00:11:11,356 --> 00:11:15,520 affect our file because we did not use -i option. 211 00:11:16,630 --> 00:11:20,030 Now, what if you want to remove first two lines? 212 00:11:20,410 --> 00:11:24,294 Well, hit up arrow key and just type one comma 213 00:11:24,342 --> 00:11:27,138 two and it will delete the first two lines. 214 00:11:27,294 --> 00:11:31,290 That's how you delete two, three, or four, or more lines. 215 00:11:31,410 --> 00:11:38,982 Now, what if you have tabs in your file 216 00:11:39,006 --> 00:11:42,150 and you want to remove those tabs with spaces? 217 00:11:42,270 --> 00:11:49,540 So if I do vi on seinfeld-characters and instead of 218 00:11:50,170 --> 00:11:58,302 spaces, I'll just put tabs, tabs, and tabs, save the file. 219 00:11:58,386 --> 00:12:01,158 You could do cat seinfeld-character. 220 00:12:01,194 --> 00:12:03,126 You see three lines have tab. 221 00:12:03,258 --> 00:12:05,234 I wanted to remove all the 222 00:12:05,272 --> 00:12:08,066 tabs inside the file with space. 223 00:12:08,248 --> 00:12:14,203 So the command to do that is sed substitute slash, 224 00:12:14,410 --> 00:12:18,602 we have to use backslash and t. 225 00:12:18,736 --> 00:12:21,038 That tells the operating system or the 226 00:12:21,064 --> 00:12:23,502 shell that this is a tab. 227 00:12:23,646 --> 00:12:26,558 Anywhere you find tab, please remove it 228 00:12:26,584 --> 00:12:30,410 with space and apply it globally. 229 00:12:30,730 --> 00:12:34,465 seinfeld-characters, you see, 230 00:12:34,465 --> 00:12:37,335 oh, didn't like something, 231 00:12:37,335 --> 00:12:41,021 [No audio] 232 00:12:41,021 --> 00:12:43,157 one second. 233 00:12:43,157 --> 00:12:48,750 [No audio] 234 00:12:48,750 --> 00:12:51,863 Oh, my mistake. 235 00:12:52,290 --> 00:12:56,362 I used backslash here. 236 00:12:56,436 --> 00:13:01,610 So I have to use forward slashes here, because this slash 237 00:13:01,730 --> 00:13:06,094 right here and this slash right here in the middle right 238 00:13:06,132 --> 00:13:08,702 here is the string that we are trying to replace. 239 00:13:08,846 --> 00:13:10,942 We are trying to replace that string with what, 240 00:13:11,076 --> 00:13:12,982 with empty line. 241 00:13:13,116 --> 00:13:14,590 So now that should work. 242 00:13:14,760 --> 00:13:16,570 And there it is. 243 00:13:16,680 --> 00:13:19,030 It did work, but it is again 244 00:13:19,080 --> 00:13:20,498 not going to impact our file. 245 00:13:20,534 --> 00:13:22,774 I'm going to use that command with -i 246 00:13:22,812 --> 00:13:25,054 option so it will make the change to my 247 00:13:25,092 --> 00:13:28,260 file and bring it back to this original content. 248 00:13:28,260 --> 00:13:30,450 [No audio] 249 00:13:30,450 --> 00:13:32,554 Okay, so now that's how you 250 00:13:32,592 --> 00:13:36,614 actually replace tabs with spaces. 251 00:13:36,662 --> 00:13:39,470 If you want to do the same thing, replace spaces with tabs, 252 00:13:39,530 --> 00:13:41,362 you could do the same thing, but just 253 00:13:41,436 --> 00:13:48,578 switch up backslash t with the second space holder. 254 00:13:48,614 --> 00:13:52,246 So you move this thing to here. 255 00:13:52,368 --> 00:13:55,618 So it will remove everywhere, let's say, 256 00:13:55,644 --> 00:13:57,360 even if you want to try it, 257 00:13:57,360 --> 00:14:00,196 t, and here I have, 258 00:14:00,630 --> 00:14:03,298 so any spaces that's in 259 00:14:03,324 --> 00:14:05,530 there, please replace it with tab. 260 00:14:07,230 --> 00:14:11,160 And I have to put this here. 261 00:14:11,160 --> 00:14:14,470 [No audio] 262 00:14:14,470 --> 00:14:17,039 Okay. So I believe 263 00:14:17,039 --> 00:14:35,125 [No audio] 264 00:14:35,125 --> 00:14:39,984 seinfeld-characters, and there you have all the tabs in there. 265 00:14:39,984 --> 00:14:41,722 I did not want to make the changes. 266 00:14:41,796 --> 00:14:43,546 That's why when I was checking it, 267 00:14:43,608 --> 00:14:45,250 it was not coming up. Anyway, 268 00:14:45,360 --> 00:14:46,920 I wanted to bring it back. 269 00:14:47,430 --> 00:14:50,338 To bring it back, I'll run the earlier command, which 270 00:14:50,364 --> 00:14:53,902 is this replace tab with spaces and hit enter. 271 00:14:54,036 --> 00:14:57,360 And now do seinfeld-characters, and you'll see 272 00:14:57,690 --> 00:15:00,622 my format is back the way I want. 273 00:15:00,756 --> 00:15:06,742 Okay, now, what if I wanted to show only 274 00:15:06,816 --> 00:15:11,354 lines from 12 to 18 from a file. 275 00:15:11,402 --> 00:15:14,750 So I just wanted to view 12 to 18. 276 00:15:14,810 --> 00:15:19,702 So 1, 2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12. 277 00:15:19,836 --> 00:15:24,062 So I wanted to see all the lines starting with J Perterman 278 00:15:24,146 --> 00:15:26,470 all the way to the end, which is the 18th line. 279 00:15:26,520 --> 00:15:29,306 I don't want it to view any of these lines. 280 00:15:29,438 --> 00:15:33,250 So for that, you'll use the command sed again, 281 00:15:33,420 --> 00:15:38,830 with -n option, 12 from 12 to 18, 282 00:15:40,470 --> 00:15:45,910 p is the option that you have to pick 283 00:15:46,020 --> 00:15:49,054 and you hit enter and you will see right 284 00:15:49,092 --> 00:15:53,630 here it's giving me from line 12 to 18. 285 00:15:53,750 --> 00:15:57,842 Now what if you want to view the opposite way, meaning 286 00:15:57,866 --> 00:16:02,714 you want to view everything except line 12 to 18. 287 00:16:02,882 --> 00:16:04,702 Then you will run the command sed, 288 00:16:04,836 --> 00:16:11,398 now don't use -n, use 12,18d this time 289 00:16:11,484 --> 00:16:16,918 and seinfeld-characters, and you'll see you have all the 290 00:16:16,944 --> 00:16:22,570 results from the top except starting line 12 to 18. 291 00:16:22,890 --> 00:16:29,920 Now what if you wanted to put a space in 292 00:16:30,790 --> 00:16:35,114 your file like every name, there should be a space, 293 00:16:35,212 --> 00:16:40,050 there should be an empty line after each character. 294 00:16:40,110 --> 00:16:45,602 So you'll do sed, just G, seinfeld-characters and 295 00:16:45,616 --> 00:16:49,922 you'll see every line has a space, empty line, 296 00:16:49,996 --> 00:16:52,238 then the name, empty line, then the name. 297 00:16:52,324 --> 00:16:53,522 This is how you could add it. 298 00:16:53,536 --> 00:16:56,430 But of course it's not going to impact our file. 299 00:16:56,610 --> 00:16:59,980 You could have that changes by putting in -i option. 300 00:17:00,970 --> 00:17:07,086 Okay, now what if you wanted to replace like, let's 301 00:17:07,098 --> 00:17:11,617 say if I have seinfeld-character and I want to 302 00:17:11,644 --> 00:17:16,634 replace Seinfeld with s or any other name, but I 303 00:17:16,672 --> 00:17:19,367 do not want to replace number line 8. 304 00:17:19,420 --> 00:17:24,137 So 1, 2, 3, 4, 5, 6, 7, 8, I want to replace 305 00:17:24,174 --> 00:17:28,925 Seinfeld with S, except the 8th Seinfeld. 306 00:17:28,998 --> 00:17:34,010 So you do sed single quote, do not 307 00:17:34,060 --> 00:17:40,454 do 8, and substitute Seinfeld with s. 308 00:17:40,612 --> 00:17:44,816 Do it globally, 309 00:17:44,816 --> 00:17:46,816 [No audio] 310 00:17:46,816 --> 00:17:48,751 seinfeld-characters. 311 00:17:50,030 --> 00:17:56,660 Okay, see it did change, oh 1 second. 312 00:17:57,050 --> 00:17:58,100 Let me see. 313 00:17:58,100 --> 00:18:01,566 [No audio] 314 00:18:01,566 --> 00:18:03,618 Now umm, 315 00:18:03,618 --> 00:18:07,230 [No audio] 316 00:18:07,230 --> 00:18:08,280 let's see. 317 00:18:08,280 --> 00:18:10,810 [No audio] 318 00:18:10,810 --> 00:18:14,989 So if I just type 8 just up to seinfeld for s, 319 00:18:14,989 --> 00:18:18,340 so it is still not doing it. 320 00:18:18,850 --> 00:18:20,560 Am I doing something wrong? 321 00:18:21,130 --> 00:18:23,246 Yes, I am doing something wrong. 322 00:18:23,428 --> 00:18:26,582 See, sometimes just tiny bit of 323 00:18:26,596 --> 00:18:28,586 a mistake makes a huge difference. 324 00:18:28,648 --> 00:18:31,674 If you notice there is no such word as seinfled. 325 00:18:31,722 --> 00:18:33,230 I put seinfled. 326 00:18:33,670 --> 00:18:36,530 Alright, it's a good exercise. 327 00:18:37,630 --> 00:18:42,302 You hit enter, you see every Seinfeld text 328 00:18:42,436 --> 00:18:44,570 or word has been changed with S. 329 00:18:44,680 --> 00:18:47,990 But now let's go back to our original question. 330 00:18:48,040 --> 00:18:50,080 I don't want to replace number eight. 331 00:18:51,010 --> 00:18:54,902 I'll fix my spelling, hit enter and you will see 332 00:18:55,036 --> 00:18:59,786 all of them have changed except line number eight. 333 00:18:59,968 --> 00:19:01,922 Now the last one I talked about 334 00:19:01,996 --> 00:19:05,202 substitute while you are in vi editor. 335 00:19:05,346 --> 00:19:10,586 So go ahead and type vi, the name of 336 00:19:10,588 --> 00:19:14,082 the file, and now you are in vi editor. 337 00:19:14,166 --> 00:19:16,051 Now what if you want to replace 338 00:19:16,051 --> 00:19:19,571 every seinfeld-characters while you are in vi. 339 00:19:19,571 --> 00:19:21,690 So you will do colon 340 00:19:23,508 --> 00:19:27,813 percent sign, s for substitute, slash, 341 00:19:27,813 --> 00:19:32,518 Seinfeld to 342 00:19:32,518 --> 00:19:34,518 [No audio] 343 00:19:34,518 --> 00:19:35,518 Peter. 344 00:19:37,027 --> 00:19:39,196 Right. You might replace everyone 345 00:19:39,196 --> 00:19:43,682 of them and hit enter, and you'll see every 346 00:19:43,756 --> 00:19:46,986 Seinfeld has been replaced with the word Peter. 347 00:19:47,118 --> 00:19:48,842 That's how you make the change 348 00:19:48,916 --> 00:19:51,294 while you are in vi editor. 349 00:19:51,462 --> 00:19:53,798 Now I want you to go ahead and try it out. 350 00:19:53,884 --> 00:19:59,894 I have also an article mentioned here in this 351 00:19:59,932 --> 00:20:03,026 lesson that you could view that article and try 352 00:20:03,088 --> 00:20:07,730 all the different commands. Again, sed command is very 353 00:20:07,780 --> 00:20:10,562 powerful if you really know inside out. 354 00:20:10,696 --> 00:20:15,026 So I would encourage you to try many different ways. 355 00:20:15,208 --> 00:20:21,842 Go ahead and do your Google, go online and search 356 00:20:21,976 --> 00:20:24,518 for anything that you wanted to do with sed. 357 00:20:24,604 --> 00:20:27,446 And I promise you, every time you will type something, 358 00:20:27,568 --> 00:20:29,618 make sure you type, like how to 359 00:20:29,644 --> 00:20:32,214 replace a string in sed command. 360 00:20:32,382 --> 00:20:34,026 Make sure you put in sed command. 361 00:20:34,098 --> 00:20:35,918 And I'm telling you, you're going to 362 00:20:35,944 --> 00:20:38,258 find tons of article out there 363 00:20:38,344 --> 00:20:42,278 people, again, have done an amazing job who 364 00:20:42,304 --> 00:20:44,678 have helped people, and you could look at 365 00:20:44,704 --> 00:20:47,210 their article and see how things are done. 366 00:20:47,320 --> 00:20:48,700 You can learn on that. 367 00:20:49,930 --> 00:20:52,466 All right, if you have any questions about sed command, you 368 00:20:52,468 --> 00:20:55,900 could just simply send me an email or message me. 369 00:20:56,530 --> 00:20:57,565 Alright, good luck. 370 00:20:57,565 --> 00:21:00,608 [No audio]