Great, show me a useful example of data exclusion with grep!Īs a practical example that advanced Mac users may find useful, we can use grep exclusion when printing and querying the command line history by looking for previously executed commands to find default matches, but excluding some selected default characters. If you test any of these options in a sample text file, you’ll find that the result is identical regardless of your approach, each omitting lines that contain targeted phrases, syntax, words, or text matches. Grep -v -e “Word1” -e “Word2” example.txtĪnother approach is to distinguish what is ruled out by grep using a pipe to separate each match, as follows: You can also use the grep file directly in the files just like before: Let’s first take the example above of using a cat in a file that is entered into grep, leaving out all the lines that match the two words “Word1” and “Word2”, this would look like this:Ĭat example.txt | grep -v -e “Word1” -e “Word2”Īll lines that contain “Word1” or “Word2” are excluded from the printed results. It’s just as simple, and there are a few different ways to accomplish this using the -v flag and the -e flag. Now that you know how to exclude equivalences of a single word, the next obvious question is to exclude multiple words with grep. How to exclude multiple strings or words with grep
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |