You can also use grep directly on files just as before as well: ![]() That’s equally as simple, and there are a few different ways to accomplish this using the -v flag as well as the -e flag.įirst lets take the above example of using cat on a file piped to grep, and exclude any lines matching two words “Word1” and “Word2”, this would look like the following:Ĭat example.txt | grep -v -e "Word1" -e "Word2"Īny lines that contain “Word1” or “Word2” will be excluded from the printed results. Now that you know how to exclude matches for a single word, the next obvious question is about excluding multiple words with grep. How to Exclude Multiple Strings or Words with grep Use whichever works best for your particular workflow. You can also use grep directly on files and exclude line matches based on words or syntax, like so: The output will be the example.txt text file but excluding any line that contains a string match with “ThisWord”. The most simple way to exclude lines with a string or syntax match is by using grep and the -v flag.įor example, let’s say we’re using cat to print a file at the command line, but we want to exclude all lines that include the term “ThisWord”, then the syntax would look as follow: ![]() Since grep is an OS agnostic utility, you can use the exclude trick in Mac OS, Linux, unix, or whatever else you have that uses grep. ![]() If you want to follow along, you can open the Terminal application and try it out yourself. Obviously you’ll want to have some command line experience and exposure to grep to find this useful.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |