![]() ![]() For more information, see Stéphane Chazelas's excellent answer to The result of ls *, ls ** and ls *** on Unix.SE. Although popular shells usually support directory-traversing ** globs, they don't always work the same way. Bash is the default user shell in Ubuntu (and most other GNU/Linux operating systems), so if you're on Ubuntu and don't know what your shell is, it's almost certainly Bash. These instructions are specific to the Bash shell. It is the shell that recurses directories in expanding the glob pattern containing **, and not grep. But don't pass -r or -R when using this method. You can pass the -a, -i, and -n flags (from your example) to grep as well, if that's what you need. The -H flag makes grep show the filename even if only one matching file is found. But if you want to use just the grep command and your shell, there is another way to do it - you can make the shell itself perform the necessary recursion: shopt -s globstar # you can skip this if you already have globstar turned on And muru has posted an excellent approach of using grep's -include option. To change the pattern type, you may also use -G/ -basic-regexp (default), -F/ -fixed-strings, -E/ -extended-regexp, -P/ -perl-regexp, -f file, and other.Building grep commands with find, as in Zanna's answer, is a highly robust, versatile, and portable way to do this (see also sudodus's answer). q/ -quiet/ -silent Do not output matched lines exit with status 0 when there is a match. threads Number of grep worker threads to use. l/ -files-with-matches/ -name-only Show only the names of files. no-index Search files in the current directory that is not managed by Git. all-match When giving multiple pattern expressions, this flag is specified to limit the match to files that have lines to match all of them. You may also combine patterns with Boolean expressions such as -and, -or and -not. Here is the syntax using git grep with multiple patterns: git grep -all-match -no-index -l -e string1 -e string2 -e string3 file So - if you want to find multiple regexps or strings in a line or paragraph or file then don't use grep, use awk. How about across a whole file? Again can't be done in grep and trivial in awk (this time I'm using GNU awk for multi-char RS for conciseness but it's not much more code in any awk or you can pick a control-char you know won't be in the input for the RS to do the same): awk -v RS='^$' '/R1/
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |