title
Linux/Mac Terminal Tutorial: The Grep Command - Search Files and Directories for Patterns of Text

description
In this Linux/Mac terminal tutorial, we will be learning how to use the grep command. The grep command allows us to search files and directories for patterns of text. You can also pipe the output of one command into grep to get certain matches. It's extremely useful once you learn the ins and outs. Let's get started... The code from this video can be found at: https://github.com/CoreyMSchafer/code_snippets/tree/master/Terminal/Grep Regular Expressions Tutorial: https://youtu.be/sa-TUpSx1JA Regular Expressions Tutorial (Python): https://youtu.be/K8L6KVGG-7o ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Linux #Mac

detail
{'title': 'Linux/Mac Terminal Tutorial: The Grep Command - Search Files and Directories for Patterns of Text', 'heatmap': [], 'summary': 'Learn how to use the grep command in linux/mac terminal for text searches, including contextual and advanced searches, with practical examples and demonstrations, and gain insights into searching and navigating text in multiple files, using regular expressions and options for advanced searches.', 'chapters': [{'end': 69.333, 'segs': [{'end': 43.277, 'src': 'embed', 'start': 0.289, 'weight': 0, 'content': [{'end': 6.034, 'text': "Hey there, how's it going everybody? In this video, we'll be learning how to use the grep command from within the Linux or Mac terminal.", 'start': 0.289, 'duration': 5.745}, {'end': 13.74, 'text': 'So grep stands for global regular expression print, and it allows us to search for some text within files on our system.', 'start': 6.674, 'duration': 7.066}, {'end': 18.244, 'text': "And this is something that you'll find yourself using all the time once you become comfortable with it.", 'start': 14.181, 'duration': 4.063}, {'end': 21.706, 'text': "So let's go ahead and look at some practical examples where you might use this.", 'start': 18.604, 'duration': 3.102}, {'end': 26.908, 'text': 'So first of all, the most basic example is simply searching for some text within a normal file.', 'start': 22.106, 'duration': 4.802}, {'end': 37.874, 'text': "So I'm here in my terminal and in my current directory there is a file named names.txt that has a bunch of random names and dummy data.", 'start': 27.268, 'duration': 10.606}, {'end': 43.277, 'text': "So let's search this file using grep to see if it contains the text Jane Williams.", 'start': 38.214, 'duration': 5.063}], 'summary': 'Learn to use the grep command to search for text within files on linux or mac terminal.', 'duration': 42.988, 'max_score': 0.289, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ289.jpg'}], 'start': 0.289, 'title': 'Using grep command in linux/mac terminal', 'summary': "Explains the usage of the grep command in linux/mac terminal, which enables users to search for text within files. it provides practical examples and demonstrates the command's usage.", 'chapters': [{'end': 69.333, 'start': 0.289, 'title': 'Using grep command in linux/mac terminal', 'summary': "Explains how to use the grep command in the linux/mac terminal, which stands for global regular expression print, allowing users to search for text within files; it provides a practical example of searching for a specific text within a file and demonstrates the command's usage.", 'duration': 69.044, 'highlights': ['The grep command in the Linux/Mac terminal stands for global regular expression print, enabling users to search for specific text within files.', "A practical example of using the grep command includes searching for a specific text, such as 'Jane Williams,' within a file named names.txt."]}], 'duration': 69.044, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ289.jpg', 'highlights': ['The grep command in the Linux/Mac terminal stands for global regular expression print, enabling users to search for specific text within files.', "A practical example of using the grep command includes searching for a specific text, such as 'Jane Williams,' within a file named names.txt."]}, {'end': 320.991, 'segs': [{'end': 100.896, 'src': 'embed', 'start': 69.493, 'weight': 1, 'content': [{'end': 73.435, 'text': 'When there are no results, it just jumps to the next line like it did here.', 'start': 69.493, 'duration': 3.942}, {'end': 80.399, 'text': "So instead, let's search for John Williams and see if that has any results.", 'start': 73.836, 'duration': 6.563}, {'end': 85.462, 'text': 'And we can see that we got two results here where it found two lines containing John Williams.', 'start': 80.779, 'duration': 4.683}, {'end': 87.504, 'text': 'and return those entire lines.', 'start': 85.882, 'duration': 1.622}, {'end': 93.489, 'text': 'Now the second line was John Williamson, but it still found Williams within this name.', 'start': 87.864, 'duration': 5.625}, {'end': 95.491, 'text': 'So it returned that anyway.', 'start': 94.17, 'duration': 1.321}, {'end': 100.896, 'text': "So now let's say that we only wanted it to return a match if it was the whole word.", 'start': 95.951, 'duration': 4.945}], 'summary': "Search results for 'john williams' returned two matches, including partial matches.", 'duration': 31.403, 'max_score': 69.493, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ69493.jpg'}, {'end': 187.666, 'src': 'embed', 'start': 160.208, 'weight': 0, 'content': [{'end': 165.513, 'text': "Now just finding those matches doesn't give us information other than knowing our text is actually there.", 'start': 160.208, 'duration': 5.305}, {'end': 167.875, 'text': "But sometimes you'll want some additional information.", 'start': 165.813, 'duration': 2.062}, {'end': 172.9, 'text': "So for example, it's common to want to know the line number of where it found our match.", 'start': 168.276, 'duration': 4.624}, {'end': 177.282, 'text': 'And to do this, we can add the dash in option to our search also.', 'start': 173.36, 'duration': 3.922}, {'end': 183.064, 'text': "So I'm just going to pull up that last search and we can add the in option onto there as well.", 'start': 177.622, 'duration': 5.442}, {'end': 187.666, 'text': "And if I run that, then we can see that now we're getting some information about these matches.", 'start': 183.264, 'duration': 4.402}], 'summary': 'Adding the in option to search provides line number of matches.', 'duration': 27.458, 'max_score': 160.208, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ160208.jpg'}, {'end': 238.174, 'src': 'embed', 'start': 211.165, 'weight': 4, 'content': [{'end': 218.53, 'text': "And this is especially common if you're searching for something in a computer program that you wrote and want to see the surrounding code of the match,", 'start': 211.165, 'duration': 7.365}, {'end': 220.49, 'text': 'and there are several ways that we can do this.', 'start': 218.53, 'duration': 1.96}, {'end': 227.332, 'text': 'so if we want to see a certain number of lines that come before our match, then we can use the uppercase B option,', 'start': 220.49, 'duration': 6.842}, {'end': 232.633, 'text': 'and you can remember that by thinking that you know I want to see the lines behind my match.', 'start': 227.332, 'duration': 5.301}, {'end': 238.174, 'text': "so I'm going to go ahead and clear the screen here and pull up the last option that we just ran.", 'start': 232.633, 'duration': 5.541}], 'summary': 'Learn ways to view surrounding code of a match in a computer program.', 'duration': 27.009, 'max_score': 211.165, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ211165.jpg'}, {'end': 300.695, 'src': 'embed', 'start': 264.489, 'weight': 2, 'content': [{'end': 269.593, 'text': 'now, if we want to see a certain number of lines after our match, then we can use the uppercase a option.', 'start': 264.489, 'duration': 5.104}, {'end': 278.479, 'text': "so i'm going to clear this out and pull up that last command and do an uppercase a instead of an uppercase b, and if we run that,", 'start': 269.593, 'duration': 8.886}, {'end': 282.602, 'text': 'then we can see that now, instead of getting the lines before our matches.', 'start': 278.479, 'duration': 4.123}, {'end': 287.806, 'text': "now we're getting four lines before and four lines, uh, or four lines after for both of our matches.", 'start': 282.602, 'duration': 5.204}, {'end': 290.448, 'text': 'and if you want to see the lines before and after your match,', 'start': 287.806, 'duration': 2.642}, {'end': 297.393, 'text': 'then you can use the uppercase C option and you can remember that by thinking that we want to see the context surrounding our match.', 'start': 290.788, 'duration': 6.605}, {'end': 300.695, 'text': 'And this is also the one that I use most often as well.', 'start': 298.153, 'duration': 2.542}], 'summary': 'Using uppercase a option displays 4 lines before and after matches.', 'duration': 36.206, 'max_score': 264.489, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ264489.jpg'}], 'start': 69.493, 'title': 'Using grep for text search and contextual search in computer programs', 'summary': "Demonstrates the usage of grep command to search for specific text patterns, including options like -w, -i, and -n, yielding two matches for 'john williams' on lines 51 and 431. it also explains retrieving lines before and after a match in a computer program, with the example showing retrieval of four lines.", 'chapters': [{'end': 194.149, 'start': 69.493, 'title': 'Using grep for text search', 'summary': "Demonstrates the usage of grep command to search for specific text patterns, including options like -w to match whole words, -i for case insensitivity, and -n to display line numbers, yielding two matches for 'john williams' and its variations on lines 51 and 431 of the file.", 'duration': 124.656, 'highlights': ['The grep command is used to search for specific text patterns within files, with options like -w for matching whole words, -i for case insensitivity, and -n to display line numbers. The chapter demonstrates the usage of grep command to search for specific text patterns, including options like -w to match whole words, -i for case insensitivity, and -n to display line numbers.', "Two matches for 'John Williams' and its variations were found on lines 51 and 431 of the file. The search for 'John Williams' using grep yielded two matches, including variations like 'John Williamson', on lines 51 and 431 of the file."]}, {'end': 320.991, 'start': 196.03, 'title': 'Contextual search in computer programs', 'summary': 'Explains how to retrieve a certain number of lines before and after a match in a computer program, using options like uppercase b, a, and c to specify the context, with the example showing retrieval of four lines before and after the match.', 'duration': 124.961, 'highlights': ['The uppercase C option allows retrieval of context surrounding the match, with the example demonstrating the retrieval of two lines before and after the match for both matches.', 'The uppercase A option retrieves a certain number of lines after the match, as shown with the example of retrieving four lines after both matches.', 'The uppercase B option retrieves a certain number of lines before the match, demonstrated with the example of retrieving four lines before both matches.']}], 'duration': 251.498, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ69493.jpg', 'highlights': ['The grep command is used to search for specific text patterns within files, with options like -w for matching whole words, -i for case insensitivity, and -n to display line numbers.', "Two matches for 'John Williams' and its variations were found on lines 51 and 431 of the file.", 'The uppercase C option allows retrieval of context surrounding the match, with the example demonstrating the retrieval of two lines before and after the match for both matches.', 'The uppercase A option retrieves a certain number of lines after the match, as shown with the example of retrieving four lines after both matches.', 'The uppercase B option retrieves a certain number of lines before the match, demonstrated with the example of retrieving four lines before both matches.']}, {'end': 630.138, 'segs': [{'end': 407.289, 'src': 'embed', 'start': 377.613, 'weight': 0, 'content': [{'end': 383.055, 'text': 'So what we need to do is use an asterisk wildcard to say that we want everything in this directory.', 'start': 377.613, 'duration': 5.442}, {'end': 389.497, 'text': 'So if I rerun that same command, but put an asterisk there and run that, then we can see that this worked.', 'start': 383.355, 'duration': 6.142}, {'end': 400.141, 'text': 'It said that it found a match in this memo.txt file on line four, and also the two matches in the name.txt file that we saw before.', 'start': 389.857, 'duration': 10.284}, {'end': 407.289, 'text': 'Now you can see that it also tried to search in this subdirectory that we have in our current folder here.', 'start': 400.561, 'duration': 6.728}], 'summary': 'Using asterisk wildcard, found 3 matches in memo.txt and name.txt files.', 'duration': 29.676, 'max_score': 377.613, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ377613.jpg'}, {'end': 463.165, 'src': 'embed', 'start': 440.121, 'weight': 1, 'content': [{'end': 447.311, 'text': "Maybe you have a lot of files and sub directories and are searching for something that you can't remember exactly what directory or file where it's located.", 'start': 440.121, 'duration': 7.19}, {'end': 452.559, 'text': "So in that case, you'd just want to search every single file and subdirectory in your project.", 'start': 447.652, 'duration': 4.907}, {'end': 457.422, 'text': 'And to do this, we can use a recursive search with the dash R option.', 'start': 452.959, 'duration': 4.463}, {'end': 463.165, 'text': 'And using a recursive search, we actually can specify a directory as the starting point.', 'start': 457.802, 'duration': 5.363}], 'summary': 'To search for files and subdirectories, use recursive search with the -r option, specifying a starting directory.', 'duration': 23.044, 'max_score': 440.121, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ440121.jpg'}, {'end': 587.236, 'src': 'embed', 'start': 560.641, 'weight': 3, 'content': [{'end': 567.663, 'text': 'And if you only wanted that information, then you can add on the "-L option and only return the files with matches.', 'start': 560.641, 'duration': 7.022}, {'end': 577.527, 'text': "So if I pull back up our last command and go back here, and I'm going to take off the N that shows the line because it wouldn't show this here anyway.", 'start': 568.003, 'duration': 9.524}, {'end': 579.749, 'text': "And then I'm going to add on the L.", 'start': 577.827, 'duration': 1.922}, {'end': 582.371, 'text': 'And this will just show us what files contain a match.', 'start': 579.749, 'duration': 2.622}, {'end': 587.236, 'text': "So if I run this, then we can see that it doesn't display the match.", 'start': 582.672, 'duration': 4.564}], 'summary': 'Using the -l option to display files with matches, none found.', 'duration': 26.595, 'max_score': 560.641, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ560641.jpg'}, {'end': 632.66, 'src': 'embed', 'start': 605.874, 'weight': 2, 'content': [{'end': 610.739, 'text': 'Now, if we wanted to see how many matches are in each file, then we can use the C option.', 'start': 605.874, 'duration': 4.865}, {'end': 614.783, 'text': 'So if we pull back up, let me clear the screen here.', 'start': 611.119, 'duration': 3.664}, {'end': 623.051, 'text': 'If we pull back up the command that we just ran and instead replace that L with a C and run that,', 'start': 615.263, 'duration': 7.788}, {'end': 630.138, 'text': 'then we can see that we get some similar output as the L option, but it also displays the number of matches in each file.', 'start': 623.051, 'duration': 7.087}, {'end': 632.66, 'text': "And don't worry about this DSStore file here.", 'start': 630.438, 'duration': 2.222}], 'summary': 'Using the c option displays the number of matches in each file.', 'duration': 26.786, 'max_score': 605.874, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ605874.jpg'}], 'start': 321.431, 'title': 'Searching and navigating text', 'summary': 'Discusses options for searching and navigating text in multiple files, including wildcard characters, recursive search, and display options, with examples illustrating functionality and potential challenges.', 'chapters': [{'end': 630.138, 'start': 321.431, 'title': 'Search and navigate text in multiple files', 'summary': 'Discusses various options for searching and navigating text in multiple files, including using wildcard characters, recursive search, and options for displaying matches, with examples demonstrating the functionality and potential challenges of each method.', 'duration': 308.707, 'highlights': ['Using an asterisk wildcard to search all files in a directory Demonstrates using an asterisk wildcard to search all files in a directory, providing examples of successful searches and potential errors, emphasizing the effectiveness of this method for searching multiple files at once.', 'Performing a recursive search with the -R option to search all files and subdirectories Illustrates the use of recursive search with the -R option to search all files and subdirectories, highlighting the capability to specify a directory as the starting point and presenting the potential challenges of conducting recursive searches in large directories.', 'Using the -L option to display files containing a match without showing the actual match Explains the use of the -L option to display files containing a match without showing the actual match, providing an example and emphasizing the utility of this option for identifying files with matches without displaying the specific content.', 'Utilizing the -C option to display the number of matches in each file Describes the functionality of the -C option to display the number of matches in each file, presenting an example of its application and emphasizing its value in determining the frequency of matches in different files.']}], 'duration': 308.707, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ321431.jpg', 'highlights': ['Using an asterisk wildcard to search all files in a directory Demonstrates using an asterisk wildcard to search all files in a directory, providing examples of successful searches and potential errors, emphasizing the effectiveness of this method for searching multiple files at once.', 'Performing a recursive search with the -R option to search all files and subdirectories Illustrates the use of recursive search with the -R option to search all files and subdirectories, highlighting the capability to specify a directory as the starting point and presenting the potential challenges of conducting recursive searches in large directories.', 'Utilizing the -C option to display the number of matches in each file Describes the functionality of the -C option to display the number of matches in each file, presenting an example of its application and emphasizing its value in determining the frequency of matches in different files.', 'Using the -L option to display files containing a match without showing the actual match Explains the use of the -L option to display files containing a match without showing the actual match, providing an example and emphasizing the utility of this option for identifying files with matches without displaying the specific content.']}, {'end': 850.551, 'segs': [{'end': 659.598, 'src': 'embed', 'start': 630.438, 'weight': 0, 'content': [{'end': 632.66, 'text': "And don't worry about this DSStore file here.", 'start': 630.438, 'duration': 2.222}, {'end': 635.303, 'text': "That's just something that pops up on the Mac sometimes.", 'start': 632.68, 'duration': 2.623}, {'end': 639.625, 'text': "Okay, so now let's look at one practical use case for using grep that we haven't covered yet.", 'start': 635.763, 'duration': 3.862}, {'end': 645.449, 'text': 'So we can pipe the output of other commands into grep to search for certain things.', 'start': 640.026, 'duration': 5.423}, {'end': 651.813, 'text': "So for example, let's say that we wanted to search our history for our latest git commits.", 'start': 645.769, 'duration': 6.044}, {'end': 659.598, 'text': "So if we just display our history, then we can see that if we wanted to find our git commits, then there's a lot of information here to sift through.", 'start': 652.193, 'duration': 7.405}], 'summary': 'Using grep to search for specific information in command outputs.', 'duration': 29.16, 'max_score': 630.438, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ630438.jpg'}, {'end': 707.214, 'src': 'embed', 'start': 672.79, 'weight': 1, 'content': [{'end': 676.073, 'text': 'so we can just run history like we did before.', 'start': 672.79, 'duration': 3.283}, {'end': 679.697, 'text': "but now we're going to use a pipe and pipe that in to grep.", 'start': 676.073, 'duration': 3.624}, {'end': 684.72, 'text': "So now we'll say that we want to grep that output for git commits.", 'start': 680.077, 'duration': 4.643}, {'end': 690.604, 'text': 'So if I run this, then we can see that it narrows down our history to lines that match our grep search.', 'start': 685.1, 'duration': 5.504}, {'end': 695.908, 'text': 'And we can even pipe this output into another grep command to narrow it down even further.', 'start': 691.004, 'duration': 4.904}, {'end': 699.45, 'text': 'So if I only wanted to see git commits about dot files,', 'start': 696.268, 'duration': 3.182}, {'end': 707.214, 'text': 'then I could run that same last command do another pipe and another grep and instead grep for files.', 'start': 699.81, 'duration': 7.404}], 'summary': 'Using pipe and grep to filter history for git commits and dot files.', 'duration': 34.424, 'max_score': 672.79, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ672790.jpg'}, {'end': 773.314, 'src': 'embed', 'start': 741.212, 'weight': 2, 'content': [{'end': 745.254, 'text': "Now I'm not going to go into detail about how to write regular expressions in this video,", 'start': 741.212, 'duration': 4.042}, {'end': 750.537, 'text': "but if you're interested then I'll put a link to my regular expression videos in the description section below.", 'start': 745.254, 'duration': 5.283}, {'end': 754.338, 'text': 'So GREP uses POSIX regular expressions by default.', 'start': 750.897, 'duration': 3.441}, {'end': 762.424, 'text': "Now, if you've watched my other videos on regular expressions, Those videos are actually using something called Perl compatible regular expressions,", 'start': 754.659, 'duration': 7.765}, {'end': 764.707, 'text': 'which is also what Python uses as well.', 'start': 762.424, 'duration': 2.283}, {'end': 767.489, 'text': 'So let me show you how this might affect your grep searches.', 'start': 765.047, 'duration': 2.442}, {'end': 770.892, 'text': "So let's say that we wanted to search a file for phone numbers.", 'start': 767.909, 'duration': 2.983}, {'end': 773.314, 'text': 'So we might do something like this.', 'start': 771.232, 'duration': 2.082}], 'summary': 'Grep uses posix regular expressions by default, while python uses perl compatible regular expressions.', 'duration': 32.102, 'max_score': 741.212, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ741212.jpg'}, {'end': 820.029, 'src': 'embed', 'start': 790.773, 'weight': 3, 'content': [{'end': 797.44, 'text': 'So this will find any three characters, then a dash, then any three characters, then a dash, then any four characters.', 'start': 790.773, 'duration': 6.667}, {'end': 799.242, 'text': 'So this should match a phone number.', 'start': 797.72, 'duration': 1.522}, {'end': 801.623, 'text': "And now let's pass in the file that we want to search.", 'start': 799.542, 'duration': 2.081}, {'end': 803.403, 'text': "So we'll search names.txt.", 'start': 801.663, 'duration': 1.74}, {'end': 808.445, 'text': 'So if I run that, then we can see that that works and that we got back the phone numbers from that file.', 'start': 803.743, 'duration': 4.702}, {'end': 812.026, 'text': "But let's say that we wanted to make our search a little bit more specific.", 'start': 808.825, 'duration': 3.201}, {'end': 820.029, 'text': 'And instead of searching for any character using the dot, we wanted to search specifically for digits using backslash D.', 'start': 812.486, 'duration': 7.543}], 'summary': 'Using regex to match phone numbers in names.txt file.', 'duration': 29.256, 'max_score': 790.773, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ790773.jpg'}, {'end': 860.54, 'src': 'embed', 'start': 830.533, 'weight': 6, 'content': [{'end': 833.096, 'text': "So we'll do a backslash D and we want three of those.", 'start': 830.533, 'duration': 2.563}, {'end': 841.262, 'text': "So I'll pass in three as the quantifier there and then a dash and then the same thing, a digit and three of those, and then a dash,", 'start': 833.236, 'duration': 8.026}, {'end': 845.026, 'text': 'then a backslash D for a digit again and four of those.', 'start': 841.262, 'duration': 3.764}, {'end': 850.551, 'text': "So now if we run this, then we don't get the results that we expect.", 'start': 845.706, 'duration': 4.845}, {'end': 856.497, 'text': "And that's because grep isn't using Perl compatible regular expressions, which is what that is.", 'start': 850.951, 'duration': 5.546}, {'end': 860.54, 'text': 'So can we get those Perl compatible expressions to work?', 'start': 856.937, 'duration': 3.603}], 'summary': 'Using regular expressions with grep for specific digit patterns.', 'duration': 30.007, 'max_score': 830.533, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ830533.jpg'}], 'start': 630.438, 'title': 'Using grep and regular expressions', 'summary': 'Explains using grep command for advanced search including finding git commits, and explores the use of grep with posix regular expressions, demonstrating searching for phone numbers and showcasing the difference in results.', 'chapters': [{'end': 740.852, 'start': 630.438, 'title': 'Using grep for advanced search', 'summary': 'Explains how to use the grep command to search for specific information within command output, such as finding git commits in the command history and using regular expressions for advanced searches.', 'duration': 110.414, 'highlights': ['Using grep to search for git commits in command history Demonstrates using pipe and grep to narrow down command history to git commits, providing a practical use case for using grep.', 'Demonstrating the chaining of grep commands to narrow down search results Illustrates the ability to further refine search results by piping the output of one grep command into another, showing a more advanced usage of grep.', 'Exploring advanced searches using regular expressions Introduces the concept of advanced searches using regular expressions, expanding on the capabilities of grep for more complex search requirements.']}, {'end': 850.551, 'start': 741.212, 'title': 'Understanding grep and regular expressions', 'summary': 'Explores the use of grep with posix regular expressions and demonstrates how to search for phone numbers using regular expressions, including a more specific search for digits, showcasing the difference in results.', 'duration': 109.339, 'highlights': ['The video does not delve into the details of writing regular expressions, but mentions the availability of additional resources for those interested, such as links to regular expression videos.', 'Demonstrating the usage of a simple regular expression to match a phone number, showcasing the pattern of three characters, a dash, three characters, a dash, and four characters, successfully retrieving phone numbers from the specified file.', 'Highlighting the difference in results when attempting a more specific search for digits using the backslash D quantifier, illustrating the unexpected outcome of the search.', 'Explaining the usage of Perl compatible regular expressions in the context of other videos on regular expressions, emphasizing its similarity to what Python uses.']}], 'duration': 220.113, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ630438.jpg', 'highlights': ['Demonstrating the chaining of grep commands to narrow down search results Illustrates the ability to further refine search results by piping the output of one grep command into another, showing a more advanced usage of grep.', 'Using grep to search for git commits in command history Demonstrates using pipe and grep to narrow down command history to git commits, providing a practical use case for using grep.', 'Exploring advanced searches using regular expressions Introduces the concept of advanced searches using regular expressions, expanding on the capabilities of grep for more complex search requirements.', 'Demonstrating the usage of a simple regular expression to match a phone number, showcasing the pattern of three characters, a dash, three characters, a dash, and four characters, successfully retrieving phone numbers from the specified file.', 'Explaining the usage of Perl compatible regular expressions in the context of other videos on regular expressions, emphasizing its similarity to what Python uses.', 'The video does not delve into the details of writing regular expressions, but mentions the availability of additional resources for those interested, such as links to regular expression videos.', 'Highlighting the difference in results when attempting a more specific search for digits using the backslash D quantifier, illustrating the unexpected outcome of the search.']}, {'end': 1203.557, 'segs': [{'end': 941.053, 'src': 'embed', 'start': 894.664, 'weight': 0, 'content': [{'end': 900.945, 'text': 'so in most of these linux and mac tutorials, all of the commands usually run the same on both systems for the most part.', 'start': 894.664, 'duration': 6.281}, {'end': 906.366, 'text': 'but these grep regular expressions are one example of something that is different between mac and linux.', 'start': 900.945, 'duration': 5.421}, {'end': 914.868, 'text': 'mac uses a version of grep called bsd grep and linux uses a version of grep called gnu grep,', 'start': 906.366, 'duration': 8.502}, {'end': 919.391, 'text': 'and you can see that version if you type grep and then dash uppercase V,', 'start': 914.868, 'duration': 4.523}, {'end': 927.18, 'text': "and you can see that here we are using BSD grep and many people prefer the GNU version of grep, and that's what I prefer as well.", 'start': 919.391, 'duration': 7.789}, {'end': 934.029, 'text': "so I'll show you a trick for how you can actually install the GNU version of grep on the Mac by installing it through homebrew.", 'start': 927.18, 'duration': 6.849}, {'end': 941.053, 'text': "so if I pull up homebrew in my browser here, so I'm just in Chrome and this is at brew.sh.", 'start': 934.029, 'duration': 7.024}], 'summary': 'Linux and mac commands mostly the same. mac uses bsd grep, linux uses gnu grep. can install gnu grep on mac using homebrew.', 'duration': 46.389, 'max_score': 894.664, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ894664.jpg'}, {'end': 1060.43, 'src': 'embed', 'start': 1033.672, 'weight': 1, 'content': [{'end': 1038.415, 'text': 'The reason we did all that was so that we could use the Perl compatible regular expressions on the Mac,', 'start': 1033.672, 'duration': 4.743}, {'end': 1043.358, 'text': 'And the GNU version of grep accepts that dash uppercase P option.', 'start': 1038.835, 'duration': 4.523}, {'end': 1047.901, 'text': 'that tells grep that we want to use those Perl compatible expressions.', 'start': 1043.358, 'duration': 4.543}, {'end': 1058.008, 'text': "So if I go back to my other window here and grab that command that didn't run before on the Mac.", 'start': 1048.261, 'duration': 9.747}, {'end': 1060.43, 'text': 'So this is still using the BSD version.', 'start': 1058.468, 'duration': 1.962}], 'summary': 'Using perl regular expressions on mac with gnu grep -p option', 'duration': 26.758, 'max_score': 1033.672, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ1033672.jpg'}, {'end': 1112.191, 'src': 'embed', 'start': 1083.689, 'weight': 2, 'content': [{'end': 1088.113, 'text': 'And we can use these regular expressions with the options that we saw before too.', 'start': 1083.689, 'duration': 4.424}, {'end': 1098.12, 'text': 'So if I wanted to do a more advanced search and see what files contain phone numbers under my current directory, then I could do something like this.', 'start': 1088.513, 'duration': 9.607}, {'end': 1105.504, 'text': 'So let me pull up the last command that we just ran and let me make this text a little larger just one more time here.', 'start': 1098.42, 'duration': 7.084}, {'end': 1112.191, 'text': 'So if we wanted to see all the files that contain phone numbers under our current directory,', 'start': 1106.445, 'duration': 5.746}], 'summary': 'Using regular expressions to search for phone numbers in files under current directory.', 'duration': 28.502, 'max_score': 1083.689, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ1083689.jpg'}], 'start': 850.951, 'title': 'Using grep command for text search', 'summary': 'Discusses using grep command for text search, including regular expressions and options for advanced searches, with examples of finding phone numbers in files, providing a detailed guide on using the gnu version of grep on a mac for greater functionality.', 'chapters': [{'end': 1060.43, 'start': 850.951, 'title': 'Using perl compatible regular expressions with grep', 'summary': 'Discusses the differences between using perl compatible regular expressions with grep on linux and mac, and provides a detailed guide on how to install and use the gnu version of grep on a mac to enable the use of perl compatible regular expressions, ultimately allowing for greater functionality and flexibility in terminal commands.', 'duration': 209.479, 'highlights': ['The GNU version of grep must be installed on a Mac to enable the use of Perl compatible regular expressions, providing greater functionality in command line operations. Installation of GNU grep on Mac.', 'The differences between Mac and Linux in using grep regular expressions are explained, highlighting the need for specific approaches on each system. Comparison of grep on Mac and Linux.', 'The technique of using homebrew to install the GNU version of grep on Mac is demonstrated, providing a detailed step-by-step guide for the installation process. Demonstration of using homebrew for installation.']}, {'end': 1203.557, 'start': 1060.53, 'title': 'Using grep command for text search', 'summary': 'Explains how to use the grep command to search for patterns of text in the file system, including using regular expressions and various options for advanced searches, with examples of finding phone numbers in files under the current directory and subdirectories.', 'duration': 143.027, 'highlights': ['Explaining the use of grep command with regular expressions and options for advanced searches The tutorial demonstrates using regular expressions and various options like uppercase P, W, I, R, and L for advanced searches with specific examples of finding phone numbers in files under the current directory and subdirectories.', 'Encouraging viewers to ask questions and support the tutorials by liking, sharing, and contributing through Patreon The tutorial encourages viewers to ask questions in the comment section, support the videos by liking, sharing, and contributing through Patreon, emphasizing the importance of feedback and support for the tutorials.']}], 'duration': 352.606, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/VGgTmxXp7xQ/pics/VGgTmxXp7xQ850951.jpg', 'highlights': ['The technique of using homebrew to install the GNU version of grep on Mac is demonstrated, providing a detailed step-by-step guide for the installation process.', 'The GNU version of grep must be installed on a Mac to enable the use of Perl compatible regular expressions, providing greater functionality in command line operations. Installation of GNU grep on Mac.', 'Explaining the use of grep command with regular expressions and options for advanced searches The tutorial demonstrates using regular expressions and various options like uppercase P, W, I, R, and L for advanced searches with specific examples of finding phone numbers in files under the current directory and subdirectories.', 'The differences between Mac and Linux in using grep regular expressions are explained, highlighting the need for specific approaches on each system. Comparison of grep on Mac and Linux.']}], 'highlights': ['The grep command in the Linux/Mac terminal stands for global regular expression print, enabling users to search for specific text within files.', "A practical example of using the grep command includes searching for a specific text, such as 'Jane Williams,' within a file named names.txt.", 'The grep command is used to search for specific text patterns within files, with options like -w for matching whole words, -i for case insensitivity, and -n to display line numbers.', "Two matches for 'John Williams' and its variations were found on lines 51 and 431 of the file.", 'The uppercase C option allows retrieval of context surrounding the match, with the example demonstrating the retrieval of two lines before and after the match for both matches.', 'The uppercase A option retrieves a certain number of lines after the match, as shown with the example of retrieving four lines after both matches.', 'The uppercase B option retrieves a certain number of lines before the match, demonstrated with the example of retrieving four lines before both matches.', 'Using an asterisk wildcard to search all files in a directory Demonstrates using an asterisk wildcard to search all files in a directory, providing examples of successful searches and potential errors, emphasizing the effectiveness of this method for searching multiple files at once.', 'Performing a recursive search with the -R option to search all files and subdirectories Illustrates the use of recursive search with the -R option to search all files and subdirectories, highlighting the capability to specify a directory as the starting point and presenting the potential challenges of conducting recursive searches in large directories.', 'Utilizing the -C option to display the number of matches in each file Describes the functionality of the -C option to display the number of matches in each file, presenting an example of its application and emphasizing its value in determining the frequency of matches in different files.', 'Using the -L option to display files containing a match without showing the actual match Explains the use of the -L option to display files containing a match without showing the actual match, providing an example and emphasizing the utility of this option for identifying files with matches without displaying the specific content.', 'Demonstrating the chaining of grep commands to narrow down search results Illustrates the ability to further refine search results by piping the output of one grep command into another, showing a more advanced usage of grep.', 'Using grep to search for git commits in command history Demonstrates using pipe and grep to narrow down command history to git commits, providing a practical use case for using grep.', 'Exploring advanced searches using regular expressions Introduces the concept of advanced searches using regular expressions, expanding on the capabilities of grep for more complex search requirements.', 'Demonstrating the usage of a simple regular expression to match a phone number, showcasing the pattern of three characters, a dash, three characters, a dash, and four characters, successfully retrieving phone numbers from the specified file.', 'Explaining the usage of Perl compatible regular expressions in the context of other videos on regular expressions, emphasizing its similarity to what Python uses.', 'The video does not delve into the details of writing regular expressions, but mentions the availability of additional resources for those interested, such as links to regular expression videos.', 'Highlighting the difference in results when attempting a more specific search for digits using the backslash D quantifier, illustrating the unexpected outcome of the search.', 'The technique of using homebrew to install the GNU version of grep on Mac is demonstrated, providing a detailed step-by-step guide for the installation process.', 'The GNU version of grep must be installed on a Mac to enable the use of Perl compatible regular expressions, providing greater functionality in command line operations. Installation of GNU grep on Mac.', 'Explaining the use of grep command with regular expressions and options for advanced searches The tutorial demonstrates using regular expressions and various options like uppercase P, W, I, R, and L for advanced searches with specific examples of finding phone numbers in files under the current directory and subdirectories.', 'The differences between Mac and Linux in using grep regular expressions are explained, highlighting the need for specific approaches on each system. Comparison of grep on Mac and Linux.']}