 This is a public service announcement. Stop catting into grep. Stop catting into grep. This is like a light on the top of your head, a siren saying that I'm a noob. Don't do it. It's a little thing. It's the smallest thing in the world, but it's hilarious when I see it nowadays. Don't do it. Don't cat into grep. There's no reason to. What do I mean by catting into grep? Okay. If you know the first thing about the command line, and you know, if you're watching this channel, you probably do. You probably know the command cat. Okay? And so here's how cat can be used. Here's how people will usually use it nowadays. You run cat on a file, and what's it do? It prints that file out to your terminal. So here's the file file has all this stuff in it. Okay? If I opened it up in an editor, that's what I would be able to edit. Cat just prints something out to the command line. Now cat is short for concatenate. What the program originated for is you can run it on multiple different files and it will put them all together as one. You know, give that as the output. Okay? But how people use it nowadays, most people think a cat is being the program you use to look at a file. And that's how a lot of people use it. Okay? That's fine. Keep that in mind. Most of you guys know this. And you also probably know what grep is. Grep is a very useful tool. So let's say we have some kind of command. So I'm gonna run pacmanq on Arch Linux that of course lists all of the packages you have. Now what grep does is you can take a command and you can pipe it into grep and you can say, let's say I wanna find all the packages that have Python in them. Okay? So I can pipe that to grep with Python as an argument and that prints out only those lines that have a match to the word Python. Okay? So here are all of my Python programs. All right? So that's how most people are familiar with grep. So here's what happens. They take what they know. If you're an introductory user, you'll take what you know about cat, you'll take what you know about grep and you do something very sensible, you put them together. Okay? So here's what people will often do. Again, here's what our file looks like. Let's say we wanna print out only those lines that have the word it in it. Here's what people will do. This is, I don't wanna say wrong, but this is a kind of a new thing to do. They will cat into, they will pipe that output into grep and let's say we look for the word it or really I can look for case insensitive it by giving it the I option. So this is what people do and I will see this all the time in scripts. I used to do this. There's no shame in it, but you don't need to do this. This is a waste of a program. There's no reason to run cat and it might seem like a nitpick, but in big scripts it begins to matter. Okay? So how are you supposed to run this? What should you really do? Well, grep of course can read standard input. You can pipe things into it, that is. But grep can also just be run on files. You can say grep the sequence it, case insensitive and run it on the file file. Okay? So there we have exact, these two things are exactly the same. It's over this one here. It doesn't have a wasteful program being run. Okay? And I don't just see people using cat. I'll see them outputting files in weird ways they don't need to. Grep can read files directly. You do not need to run cat into grep. Same thing, people do the same thing with said. Okay? Do not do what I'm doing right here. Do not cat out file and pipe it into anything. This, if you ever write this, you're doing it wrong. People will do it with said. Let's say, oops. People will say, oh, let's replace the word it with capital it, however many instances on a line. Now that, again, that works. Don't, you don't need to do it. Get rid of that. Oops, sorry. Get rid of cat all together and just run it directly on the file. You can run it on multiple files too. Okay? Now here's where catting into grep is especially stupid because here's one of the differences. Let me actually show. So let's say we have cat both file and another file into that same grep command. Okay? Again, we're looking for it. There's our output. Now let's say we run grep directly on those files. Okay? File and another file. If you run grep directly on these files, you actually get more output. You get better, you get more information because grep can tell you which one of those files it matched in. And this is really helpful. Especially if you're on the command line, let's say you run some find command looking for some sequence that's in a bunch of files. Well, you could just run grep on those files and get not only where you find the match but what file it's in. Okay? So grep actually gives you more information if you run it directly. Now you might say, well, Luke, I don't want this output. This is bloated. I don't want the file name. I just want this stuff. Well, no big deal. How you do that is actually in general, instead of saying cat file, you can always just say open angle bracket and file and that does the same thing. And the difference between a cat and open angle bracket is you're not evoking this extra program cat. It actually is less intensive on your computer and stuff or your CPU and all that stuff. Okay? You're not allocating memory for this or calling this extra program. So you can just, if you wanna run, if you do not want all the other stuff where, you know, if you have multiple files, let me actually show you the output again. If you do not want this, the purple stuff here, you can just say file, another file, grep it. Okay? That's how you do it. What I'm trying to get at is that cat is basically a useless program. You shouldn't really be using it because you can get the same functionality from just using other programs the way they're intended to be used or with the output file thing. Oh, I will say one cautionary tale though, right? So be careful. You can run this. Actually, I'll give the example here. Let me actually copy file to new file, something like that. So I can output that with open bracket, but do not run this with closed bracket. You guys know what that does. Actually, let's see what that does. It will get rid of everything in the file, right? So be careful not to use it because you'd be basically what you're doing when you're doing this. This means like output something to that file and it opens that file up at the very beginning and basically blanks it, okay? So you can't access it. So be sure to use the open to output things if you wanna have the open, the bracket thing, not the closed one. But anyway, so that's just the minor lesson. Don't use cat. If you're using cat, you're probably doing something wrong. And the reason I say this, again, it's a minor nitpick. It's not like cat is a bloated program that's gonna destroy your scripts or something like that. But it's one of those things, just bear in mind how your programs work. Grap can be run on files, okay? It's no problem, just know how it works. Check your manuals, check everything else, check man grep and figure it out for yourself if you don't know. But you know, stay limber, stay mentally limber. Anyway, minor nitpick, I'll see you guys next time.