regex - GREP with wildcard, but exclude a specific term and return file name -
regex - GREP with wildcard, but exclude a specific term and return file name -
i'm new using grep , need perform quite complicated query here goes:
i recursively grep directory string: ====\d+
\d+ 1 or more decimals (perl syntax) , string different ====0
.
i want grep homecoming file name of file containing ====\d+
.
to show file names without paths, do
grep -erl '====[1-9]\d*' . | while read name; basename $name; done
or, if file names can contain spaces, newlines or other strangeness, use
grep -zerl '====[1-9]\d*' . | while ifs= read -r -d '' name; basename "$name"; done
the grep
flags used (from gnu grep
's manual):
-e, --extended-regexp interpret pattern extended regular look (ere, see below). (-e specified posix.) -r, --dereference-recursive read files under each directory, recursively. follow symbolic links, unlike -r. -l, --files-with-matches suppress normal output; instead print name of each input file output have been printed. scanning stop on first match. (-l specified posix.) -z, --null output 0 byte (the ascii nul character) instead of character follows file name. example, grep -lz outputs 0 byte after each file name instead of usual newline. alternative makes output unambiguous, in presence of file names containing unusual characters newlines. alternative can used commands find -print0, perl -0, sort -z, , xargs -0 process arbitrary file names, contain newline characters.
regex string grep filenames
Comments
Post a Comment