![]() If your Busybox has ash and a decent test, you can write a recursive directory traversal in the shell. If you don't have find, it gets complicated. If there are many files, you can use a for loop over all the files (still ash-only because of the command substitution). ash and not hush), and there aren't too many files to consider, you can generate the list of file names with find and pass that as an argument to grep. If you have find but it doesn't have -exec, and your file names are tame (no newlines or \[*?), and your shell supports command substitutions (i.e. something will always match from the beginning of the line because that gives the left-most longest match. set -f IFS for x in (find /some/dir -type f) do grep -H PATTERN 'x' done set +f ¹ No -exec + on Busybox. In sed, regular expressions match the left-most longest. If you have no suitable xargs, you'll need to invoke grep on each file name separately: find /some/dir -type f -exec grep -H PATTERN \ Thus, it will not work with busyboxs builtin grep, nor with the default grep on BSD/Mac OSX systems. If your file names are tame (no whitespace or \'"), you don't need -print0/ -0: find /some/dir -type f |xargs grep -H PATTERN matches a portion of a subject string that is identical to itself. Most characters are ordinary: they stand for themselves in a pattern, and match the corresponding characters in the subject. If support for -print0 and -0 are compiled in, then you can use xargs to invoke grep for many files at once¹: find /some/dir -type f -print0 | xargs -0 grep -H PATTERN A regular expression is a pattern that is matched against a subject string from left to right. ![]() Combine find to traverse directories recursively with grep.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |