You can perform a recursive case-insensitive search in a directory and its subdirectories: $ grep -ir word dirname First type your search term, and then the file to search: $ grep word filenameīy default, grep performs a case-sensitive search. Most of us know how to use grep in simple ways, like finding all occurrences of a word in a file. I suggest making a plain text file to use for practicing the following examples because it limits the scope, and you can quickly make changes. That is why you see the phrase “pattern matching” when you’re studying grep and other GNU text-processing tools. We humans tend to think in terms of the numbers, words, names, and typos we want to find, but grep doesn’t know about these things it looks for patterns of text strings to match. Which sounds like fun, but if you use only Linux then you don’t need to worry about any differences. There are some differences between GNU grep and Unix grep, and these are often discussed in documentation and forums as though we spend our days traipsing through multiples Linuxes and Unixes with gay abandon. It’s unlikely that you will bump into a non-GNU grep on Linux unless you put it there. You can verify that you have GNU grep, and not some other grep: $grep -VĬopyright (C) 2014 Free Software Foundation, Inc. We’ll stick to GNU grep and the Bash shell, because both are the defaults on most Linux distros. GNU grep is an amazing power tool for finding words, numbers, spaces, punctuation, and random text strings inside of files, and this introduction will get you up and running quickly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |