sudo grep 'string1|string2|string3' /home/nl/test.txt Code language: JavaScript ( javascript )Īlternatively, you can navigate into /home/nl and do the grep search. Suppose you want to search for multiple strings in a single file located in /home/nl/test.txt, and you want to do it in a single run, use the command below. In both cases, grep will output all the lines that might contain any of the listed patterns. command | grep 'pattern1|pattern2|.' Code language: JavaScript ( javascript ) What we’ve just did is asking grep to look for multiple patterns (pattern1, pattern2, …) in a file.Īlternatively, we can pass (pipe) the output of another command to grep to search it for required strings by running the following commands. sudo grep 'pattern1|pattern2|.' /path/to/file Code language: JavaScript ( javascript ) In other words, you have to use | instead of | in a grep command. grep use | symbol to separate two patterns in a command.īut before you actually use it, remember to escape it so that grep doesn’t mistakenly recognize it as part of the pattern. You can use the | symbol to grep multiple strings or patterns. If you want to search multiple patterns or strings in a particular file, use the grep functionality to sort within a file with the help of more than one input word in the command. If you walk through the docs, you'll find a lot more *nix-like command-line tools, including cut, tr, and on the 7K, sed and some other goodies.Īlso, don't overlook the prev and next modifiers for 'include' matches.6 Grep in multiple files Grep Multiple Strings You'll then want to search "fun" (what else?) to find the Fundamentals Configuration Guide (which contains the Regular Expression section in the Understanding the Command-Line Interface chapter).Įaster egg? Chapter numbers are in binary for this doc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |