![]() ![]() Notice that the last example using -C 1 to grab both the preceding line and trailing line shows four results in the last match. Matches are shown separated with a “-” line so you can clearly see the context for each match in the presented results. These options let you specify the number of trailing, preceding, and both trailing and preceding lines to print, respectively. The -A, -B, and -C options to grep let you see a little bit more context than a single line that matched. Samples of text and seeking those samples there can be many matches but not all of them are fun so start searching for samples start looking for text that matches $ grep -i this sample.txt This is the sample file. ![]() It contains a few lines of text that we can use to search for things. $ cat sample.txt This is the sample file. As you can see, the only matches for the string “this” are the capitalized string “This”. I limit the search to only text files in the current directory *.txt and the -i option makes the search case-insensitive. One of the most basic ways to use grep is shown below, looking for the lines of a file that match a pattern. ![]() Grep can check the file that you specify or can search an entire tree of your filesystem recursively looking for matching files. You can use grep to see if a file contains a word or use one of many forms of regular expression to search for a pattern instead. The grep command is a very powerful way to find documents on your computer. Learn the basics of grep with this tutorial from our archives. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |