099 | GREP

099 | GREP

Hi, this is Wayne again with a topic “099 | GREP”.
Foreign, hey friends, it’s Ryan here and we’re back with another level: 099 video to teach you all that stuff that we’ve only been pretending to understand in the conference room today. We’Re going to talk about grip grip is a Search tool, but unlike find we’re not searching for file names, we’re searching file contents, then Linux, nearly everything is a file, so it makes this a very powerful tool. We can find almost anything using grip and you’re not limited to Linux here, because with Windows subsystem for Linux, you can enjoy these same exact commands on Windows and for those of you with mental disabilities, Mac OS terminal app will also let you use grip, I’m going To use WSL for my demos here and the basic Syntax for grip is pretty simple. It’S just the word grip, then any modifiers that you might need and then the text that you want to search for and finally, the target of your text. The target of your text is usually a file, although it can also be a directory in some cases, and you can even use Wild Card Targets in our example here, the dash I modifier denotes case insensitive Now by default. Grip will match case. So, let’s look at how this would work if you didn’t match Case by looking at the file contents, that shot is actually something that gets used a lot, at least in my grips, because usually your data is not going to be reliably cased.

Now somebody who’s a beginner to Linux or uses it infrequently. One of the best real world uses of is to search your history, though. It’S not uncommon to need to use the command line, to install some obscure drivers or install things from a package manager. And if you don’t do that every day, it’s easy to forget the exact syntax of what you’re doing, but by piping the standard output of your history into a grip search.

You can easily track down those past commands that you did months ago without scrolling endlessly through your history, now note that, when we’re passing standard output to grip, we don’t need to specify Target grip knows that the standard output is the target. If you don’t understand, standard output and what’s going on here, don’t worry because we got you covered with another 0.99 video that will teach you about that. You can pop anything that outputs standard output to grip. You can even pipe the man page for grip into grip while searching for grip. Now I use history search a lot on my media server when running YouTube, DL or ffmpeg commands.

Both of those programs have some long commands with a lot of modifiers and a lot of things that can be different when you use them on different sites or different cdns may be used for audio, maybe used for video using wild cards. I can go back through my history and search for specific domains to see what YouTube DL syntax. I need to use for that domain. In case I haven’t used it in a while also note that there’s a wild card here, but this isn’t quite the same as a wild car that you’re used to seeing on your command line. This wildcard is using regular expressions and regular expressions are maybe the most powerful tool that you can use when using grip. I’M not going to tell you how to use regular expressions in this article, but you should definitely check that out more to get a better understanding of it. Let’S say you have customer data and flat files and you need to find everyone at a certain street name, but any Street number and the zip codes even change on that same street, which sounds wild. But there’s a real world example and your ZIP codes need to match the first two digits. Now that’s a crazy request. That would be easy to do with SQL or something like that, but in a file system.

How are you going to do it? Well, it turns out grep can do it fairly easily, using regular expressions now you’ve seen the dash I modifier and, like I said you are going to get some nasty data in the real world. It’S never going to be perfectly cased. It’S never going to be perfectly formatted. Basically, the only data you get out there in the real world in the streets is bad data, so Dash eye is really helpful. I use it almost all the time and another really super useful modifier is the dash r or the recursive grip search.

099 | GREP

Recursive search will dig into every subdirectory of your target directory and search the whole tree from that point for whatever you’re looking for. This is massively useful when you can see the result of something, but you can’t find the code that is causing that thing such as you know, looking at output on a web page or if you’re getting error, output and a program you’ve written or that somebody else Has written and you want to find hey, what’s outputting this error, you can often grip for the actual words in that error and find where, in the program it’s being thrown, if you’re a developer someday, you will probably be tasked with taking over someone else’s broken project And grip will be indispensable for finding stuff like that when you find yourself in that situation. Another great example of where recursive grip is really useful is when you’re working with aggregated, JavaScript or css, and you only see the big file, the big aggregated file and you need to search through all the little individual files. Next up for useful modifiers. We have the dash V modifier, the dash V modifier is inverse, so this Returns the inverse of what you’re searching for so a real world example. Here is imagine that you have some logging going on and you’re logging all of the IP addresses and timestamps of who accesses your server, and you know the IP addresses that should be accessing your server. So using grip inverse you can do a quick search for any IP address. That is not the IP addresses that you were expecting and thus you can see any intrusions that might be happening in your server, but wait I hear you cry out. You didn’t introduce the dash e-modifier there and you’ve used it already. That’S right, I used it before I introduced it to tease it early and pique your interest and therefore make it easier for you to remember.

099 | GREP

There’S no need to. Thank me. It was my pleasure. The dash e-modifier is one of several ways of denoting an or condition in your grip command, so you can do logic and grip commands.

This is the most readable, but there’s also some shorthand I’ll. Let you look that up on your own. You might also see commands like egrip and F grip, but those commands are actually mostly deprecated now so you’ll see them a lot if you’re doing Googling about grip, but you shouldn’t use them. You should get used to using the modifiers because, like I say, they’re deprecated they might take them out someday now we’re almost at the end of this 0.99 journey.

099 | GREP

I just want to introduce one more thing because or isn’t the only logic that we can do. Of course, you’ve already seen dot dash V, which is not so you have or and not, but what about and well and is actually quite easy to obtain in grip just by daisy chaining, your grips into and piping them into other grips. Now again, if you don’t understand standard input, standard output follow the length of the other 099 video and you’ll get even smarter today, which you probably weren’t, expecting now, there’s a lot more to grip, and it can be even more useful to this. But this is level 0.99 and with that we’re getting solidly into level 100 territory and you are becoming a grep star and when you’re a star you can just walk up and grip them by the file system, so get out there and start gripping today.

.