 So I put up a video a couple hours ago on the importance of writing efficient scripts And I showed off this script, which is something I had written to auto generate shortcuts And one of the predictions I made that immediately once I put it up a lot of people are going to tell me ways to improve it Now of course in the last video I talked about big improvements that I that made it extremely fast And much more efficient than it used to be when I was looping through this list and outputting to file after file after file But there are some other optimizations that a lot of people mentioned and I just wanted to sort of talk about them just to I guess Have them in your brain Now first off I had these directory shortcut The well the directory shortcut and the dot file shortcut commands which are sort of syntactically similar And a lot of people noted that I was using both said and awk and you can actually get away with only using one of them Now there are a couple people who recommended only using awk here. So I have implemented I have another copy of the script where instead of Taking running set on the folders File and to get rid of all the commented lines Instead we can go over here and you see that we actually can do just one single awk command We still have the print command here But we also have this thing here, which is really just a regular expression that says don't print any of these lines that begin With a pound sign. That's all this says So this is actually a slightly faster way of doing the same thing again. It's it's marginally faster Inperceptibly faster, but of course that kind of stuff adds up and it's important to write things up that are just a little bit quicker But that's not the only optimization, but let's go ahead and look at this. So if I run a time on this This is the original script. We're getting around 50. Let's see. There are other ones that are more like mid 50s up as 60 milliseconds or something like that if we wanted to run on this We usually get low 50s. Oh, there's some 40s and stuff like that. So it's a little bit faster tends to be so, you know, just Let that known now one of the other things that I had talked to some people in the comments about Is notice that what we're doing here in these awk commands for each one of these awk commands are actually I mean, they're all working on the same folder. So this one runs an awk command on folder This one runs an awk command in folder So it's accessing the folders file three times and I think I might have said there's something like this in the last video There's probably a way to to be able to just access it once and then have different commands And there is a core. I was talking to someone in the comments section Yeah, there is a core utility called T which does this for you and while I was trying to figure it out Actually someone up here. This guy and Ray actually gave I'm not familiar with T But we can go over it but he gave a simple solution So just to show you how T works because it's not it's one of those utilities that people don't use as much So let's make Some kind of directory here and go into it. So let's say we'll create a file So here's some content and we'll put this into, you know input file So now we have, you know, this input file that has this stuff in it, okay So what T does basically is you can let's say we can cat input file into T And let's say we want to put that input into, you know new file or something like that And what it does is it puts that input into new file and it also prints it to standard output So the reason this thing is called T is because it's one of the command It's a command that basically forks the stream It puts part of the stream in a file and it prints part of the stream out And in fact you can, well actually let's just verify that that did go into that file. It did indeed You can also do something like let's say cat input file You can choose multiple files here. So I can say file one, file Two, file three And it's still going to print the standard output But it's also created all of these files and all of them will have that same output in it So that's basically how T works now the thing about it is I can show you another revision of the script And in this one we only access the folders like the the actual input file once And this one I do did it a little different. I actually have it access it with a said command In the reason I have that You know the script before we integrated the set the getting rid of the comments into the awk command But it actually works better to do it instead here because you call the file and automatically get rid of The the commented lines or whatever and then what happens is we use T And instead of putting the output into a file We use what it what it's called a process Oh god, there's a name for it someone's going to this thing right here So you're so normally supposed to output to a file, but you're outputting to a process It's probably just called process output or something process substitution. I think that's what it is Okay, I just know them by what they look like so when you have We have something in parentheses and You know a bracket going towards it that just means it's a Process substitution and this is I think only part of bash just so you know, I don't think it's in Your standard like shell or your posix compliant shell But anyway, so what this is doing Is instead of accessing the folders file three times For the three things we print out Basically what it does is it takes t and then it outputs This process substitution So it takes that output and it runs the awk command we need and then it puts it in the the actually the actual file We need the same thing. So we have the three files two of them are process substitution And then the other one we just have you know the Plane output going where did it go? Okay. Yeah, right right here So we just the last one we just take that output and pipe it to a normal awk command And that's the reason we do this and instead of a process substitution is because t no matter what is going to print stuff on It's going to print stuff on to your actual shell and standard output So that's why you want to if you don't want it to do that you can just you know pipe it into something else. So let's say Well, it doesn't even matter you get the point though. So we can do something like that So anyway, that that's about it. So I just wanted to do this just to give the the people credit who you know came up With the different solutions. So as I said, you know, people always give you feedback if you put them out there But oh, yeah, let's run. Let's see how quick this one is So new is shortcut. So you got low low forties got 30 milliseconds. So this one is Considerably faster than the other two because it's really doing it in the most efficient way It's only accessing the files once so anyway, this is just a small addendum. So I'll see you guys next time