 Okay, this is the first in a series on SED. SED is an application that I use regularly. I think a lot of shell scripters use regularly. SED stands for Stream Editor. And basically it allows you to manipulate text files, substituting stuff, replacing stuff. There's a lot that can be done with it. And a lot of us, like myself included, use it for the very basics. But I thought it would look a little more into what we normally do and actually look at it just a little bit more than I've thrown out in the past. Before I get started, I want to mention, because someone will complain about this, the title of this video, at the end I have the word bash. It says Linux shell bash. Someone will complain that this has nothing to do with bash, although you use SED within bash. And I'd put that in the title basically because most people who are going to be looking for this video are probably going to be searching for that. And when people come to my site, I want them to be able to search either shell or bash. And I want this video to show up. So that's why I put that in the title for any of my command line videos, even if it's not bash specific. Anyway, here we go. Real quick, I've already created a little text file here called text. And it just has some random stuff I typed in it just for to have me give me something to work with. We got a line says 10 tiny toes. This is that. Five funny zero, one, two, three, and tree twice. Okay. So we're going to look over very basic substitution. We'll get into more advanced stuff in the future, but this is some basic things you may want to know. First off, you can use SED a few different ways. We can cat the file into there. In fact, I'm going to quickly copy. No, no, I'm going to leave that. Okay. You can cat out the text file and pipe it into said like so. And then what we can do for substitution, we're going to say substitute forward slash forward slash forward slash. And we're going to give in between the first and second forward slash what we want to replace what string we want to replace and second one, what we're going to replace it with. So for an example, I can say T here and then here I can put an uppercase T because we're going to be replacing the lowercase T's with uppercase T's. If I hit enter at this point, we'll see the lines from the text file, but we have only modified the first T in each line to be capital. You'll notice that the second T and the third T and the other T on that line. It doesn't. So basically at this point, we haven't modified the original file. We've just displayed a difference. So if I cat out the text file again, you can see that nothing has been changed. So we haven't changed anything yet. We're passing it information. So before we move on to making the other T's uppercase, I commonly do this. I cat things into it. I pipe things into it. I should say, and this is good if you're piping the output of another program, but really that's not necessary because what we could do is just at the end of our command here, say the name of the file, and it does the same thing. So the need for piping is not necessary, but is how I commonly do it, just a habit of mine. So I wanted to point that out. So our command right now is said. And inside our quotations here, we're saying we're going to substitute, that's what the S stands for, lowercase T for uppercase T inside this file. Once again, not modifying the file now, just displaying it on the output different. So to make it so that we can change the other T's on the lines other than the first T on each line, we want to change it by putting after our last forward slash here a G, which stands for global, meaning find all the lowercase T's and transform them. So there we go. That's what we've got now. We've got every T is now an uppercase T on every line. Again, we have not modified the actual file yet. If I cat out that file again, you can see we still have all lowercase T's clear the screen. I'm clearing the screen by hitting Ctrl L or you can type clear. So at this point, how do we actually modify that file? Well, we can create a new file by redirecting into it. So we can take the output of this and put it into new.txt or whatever you want to call it. So now I can cat out new.txt and you can see that it's the old file but with the T's replaced. But if I cat out text, you can see that it still has all the lowercase. So we have not modified the original file. If we wanted to modify the original file, what we can do is forget about piping that. We're going to say said and then we got our command here and the file. Well, we want to edit inline. So we're going to say dash I and that's just saying to edit the original file, modify the original file. So now if I hit enter and there's no going back after this, I mean we can always we will reverse it but there's no undo. So make sure you want to do this. Normally to be safe, I usually pipe in a new file and then maybe rename the old file or something just all depending on what I'm doing. But you see we get no output because it wasn't displaying the changes. It was just making the changes. Now I can cat out that original text file and you can see that we have modified it. Of course, in this particular scenario, we can change it back by changing all capital T's to lowercase T's inline because we have our dash I. I'm pretty sure I means inline. That's what I've always said to myself. I'm not sure if I read that somewhere or made that up. But dash I means change it in place in place. Maybe it stands for it. Let's see. So now if I cat out text, you can see we put it back to how it was because we just went through and took all T's all capital T's and made in lowercase T's. Now if we had a file that originally had uppercase T's and lowercase T's and we changed all them, it'd be kind of hard to go back without a lot of script foo because you'd have to know where all the other ones are and if there was no pattern, then you kind of screwed. So if you are to use this dash I, make sure that you really want to change that file or at least make a backup copy if it's an important file. And of course, I'm just using T's in this beginning tutorial just to keep things simple. And you can replace full strings or full lines. So at this point, I'm going to say this replace this with that. And if I hit enter, I'm going to do it. I'm not going to do it in line. I'm going to do it here. I'm just going to display it. I'm removing the dash I. So we're not modifying the original file. I'm going to hit enter. And there we go. We can see now line two, what you say this twice now, this is that now says that is that. Again, I removed the I so we did not modify the original file. So this is our first tutorial. I know this is very basic. This is stuff that we've done in the past. We're going to get into a little more advanced stuff in coming tutorials. But I just wanted to start off with something simple. I thank you for watching. Please visit filmsbychrist.com. That's Chris Decay. There should be a link in the description. Check that out. And I have plenty of videos out there, and more to come in the coming weeks on said so for the next couple of Mondays, because Mondays is kind of a shell tutorials or operating system tutorials dealing with Linux. And we're going to be looking at said in depth over the next couple of weeks. Again, thank you for watching. Visit my site and I hope that you have a great day.