VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » IT, programs, coding
Search For Patterns Within Files With Grep DistroTube

Search For Patterns Within Files With Grep DistroTube

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Search For Patterns Within Files With Grep DistroTube One of the most important command line utilities that every Linux user should know is Grep. Grep searches one or more input files for lines containing a match to a specified pattern. By default, Grep outputs the matching lines but it has a ton of flags and options available. ERRATA: I mentioned that Grep doesn't like binaries. That's not entirely true. There is a way to grep a binary as if it were a text file by using the -a flag. One thing to note though is many binaries are just one gigantic line so a lot of the time, all you are going to get is the equivalent of a cat binary-file. - https://www.gnu.org/software/grep/ - GNU Grep
Date: 2022-03-30

Comments and reviews: 9


Thanks for posting this. Something a little different than tiling window managers et al.
cat is actually for taking 2 or more files and catinating the output. So, sticking grep at the end of cat is perfectly fine. Or if you are looking to edit specific lines you can cat the file, use grep, and then use sed. Stick awk in there to the search ny a specific colum, then send it to lpr to print it out.
The whole point of UNIX and Linux is streaming information, which is how the command line is set up. MS-DOS is the same way, with less utilities already available. You'd have to write a program to do things like grep, awk, and sed.

reply

Another very cool use for grep is when using ps -ef to list all processes. You can grep to filter specific info like a process name, or user name. Pretty much any process. EG-You can use that to determine what the process ID number is of a specific process that isn't working properly in order to use kill -9 the process ID if it were giving you trouble and needed to be shutdown.
For example:
ps -ef - grep bash
ps -ef - grep username
etc.....

reply

My favorite grep function acts like sed. Extract a substring from a line that contains a string that doesn't have to be part of that substring.
echo -e -now\nis the time for all\ngood--grep -Po -the \K.-?(?= for)-
grep -Po -wlan0.-inet \K.-?(?=/)-

reply

Not using more commands or programs than necessary is not really important for use on the command line. But it is useful in scripts, as it potentially reduces dependencies and runtime.
reply

Can you do a video/stream where you let your viewers send in links to their dotfiles to be critiqued by you? It would help highlight good and bad practices found in such files.
reply

Hey DT, regarding streaming cat into grep because you just used it, the better way is writing the grep command and pressing alt-. To bring the argument from the previous command.
reply

Grep is full of bloat and clearly violates the Unix philosophy. Instead of doing only one thing right, it does also read files and count lines. Worse feature creep than SystemD.
reply

Do you plan on doing a video on text manipulation in the command line? I have touched on it using sed but I realise it's the tip of the iceberg
reply

you should use ripgrep, it is a FAST grep, so much faster ... and used with fzf ,,, it give you a fuzzy search in term or VIM
reply
Add a review, comment






Other channel videos