Search for multiple strings in several files with Sublime 3

∥☆過路亽.° 提交于 2019-12-17 23:06:08

问题


I know how to search for a single string in several files at once with Sublime 3 (explained here).

What I need to do is to search for multiple strings in several files. I've tried going to Find in files and setting:

Field:  string1 \& string2
Where: /path_to_folder_containing_the_files_I_want_to_ search/

(where string1 and string2 are the strings I want to search for) but that doesn't seem to work.

Can this be done at all?


回答1:


Just came across this old question and thought I'd add my solution, which may be useful for somebody in the future.

Sublime supports searching in all open folders and can use regex. So utilizing both, you can open or add all folders you want to search in to the project and use regex to search for multiple keywords. In your case it would be the following (make sure to check the regex box .* icon):

Find: (string1|string2)
Where: <open folders>



回答2:


I use this:

checked Regular expression

Find: (string1.*string2)

Where: *.php



回答3:


I tried this on Sublime Text2, so should work on Sublime Text3 as well.

Field: string1 string2 string3 string4 Where: /path_to_folder_containing_the_files_I_want_to_ search/

Note: uncheck '.*' which means Regular Expression and check "" which means look for the whole word.

This will search for the pattern "string1 string2 string3 string4" in all the files in the mentioned folder.




回答4:


No, you can only search for one thing at a time in Sublime, like most other editors I'm aware of. The only possible way around this is to use regex search (click the button at the far left of the field when entering your search term) and come up with a good regex that matches all the things you're looking for. Or, you could just search for each match one at a time.

As an alternative, consider brushing up on standard command-line text-processing utilities like grep, sed, awk, etc. Combining their power with the shell's command piping capabilities allow you to run commands like:

grep -e "foo" *.txt | grep -e "bar"

which will search through all .txt files in the current directory for the pattern foo, then all resulting lines will again be searched for the pattern bar, so that the final output will have both foo and bar in them, in any order.



来源:https://stackoverflow.com/questions/25689180/search-for-multiple-strings-in-several-files-with-sublime-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!