With -P (PCRE) option you can replace the ] with \s (this would look much nicer): grep -rlzP 't\s*h\s*i\s*s\s*i\s*s\s*s\s*o\s*m\s*e\s*\ On the other hand, if the whitespaces can come at any places rather than the words, this would loose its good look: grep -rlz If you want to print the matches also, use -H instead of -l. Grep -l will print only the file names that having any of the desired patterns. So, we can use it to match all the whitespace characters that can come in between the words. ] character class pattern indicates any whitespace characters including space, tab, CR, LF etc. The main trick here is -z, it will treat the each line of input stream ended in ASCII NUL instead of new line, as a result we can match newlines by using usual methods. So, simply: grep -rlz 'this]*is]*some]*text'. choose files of which directory to exclude. find can be used to be selective on the files to search e.g. If you just want to search all files recursively starting from current directory, you don't need find, you can just use grep -r (recursive). type f -exec grep -lz 'this]*is]*some]*text' +Ĭonsidering the whitespaces can come in between the words only. Get the MDN newsletter and never miss an update on the latest web development trends, tips, and best practices.With the newer versions of GNU grep (that has the -z option) you can use this one liner: find. Previous Post Introducing AI Help (Beta): Your Companion for Web Development Next Post Reflections on AI Explain: A postmortem Stay Informed with MDN Let us know if this post has been helpful for you, if there are other ways you are using grep that I haven't mentioned here, or if I've missed something you think is important. If you enjoyed this post, let us know in our community Discord or on GitHub to share your thoughts, ask questions, or just to say Hello! The recent blog post New reference pages on MDN for JavaScript regular expressions describes the updates we've made to the documentation to help you find what you're looking for and understand the syntax. If you think grep might be interesting for you, we've recently updated our regular expressions reference pages that will help you check patterns as you're searching. I think that learning grep will be one of the best steps you can take for boosting productivity when writing code, debugging, inspecting new projects, or doing some quick analysis of a project. Grep is so useful to me that it's muscle memory to type grep -r to prepare a search for a given pattern. So let's dive in and find out how to put some grep in your step! If you're unfamiliar with grep, this post will cover the basics, some common examples, including how I use it every day, and why I think it's an essential tool for developers. In this post, we'll see what grep is, what it can do, and why I think it's one of the most powerful command-line tools you will use when working with code. You'll quickly realize that you need an efficient tool to help you with the different kinds of searches you need to make that's where grep comes in. You might use your Integrated Development Environment (IDE) to search project files, your operating system's file search, or even code search through GitHub or another code hosting service. Searching through code and text is one of the most common tasks you'll be performing while you're building for the web. You might want to search for a variable, where an error message originates, a CSS class, an image used in HTML or markdown source, logs from your application – the list is endless. Wherever you are on your web development journey, you'll be searching for text or patterns in your code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |