Amid a bunch of subfolders, how do I enter only into those that contain a specific string (e.g. 1h2s) while looping through the array {1h2s,1kqf,...} and do grep? The full name of a subfolder consists "oligomerAngle-1h2s" OR 1kqf etc. plus a bunch of irregular numbers
use find:
find . -type d -name \*1h2s\* -exec grep search {}/* \;
find .
search in current directory downwards -type d
means only find directories -name \*1h2s\*
match only directories with this name (you need to escape the * from the shell) -exec grep search {}/* \;
run grep on each file in the found directories
NOTE: this will cause some error messages from grep if there are no files in the found directories or if there are sub-directories, you could add 2>/dev/null
to the command if you didn't want to see them
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments