linux - Matching file extensions inside content with grep ('*.log' is an error) -
i'm trying search each line see lines have any_filename.log
the below codes aren't working
find . -print | xargs grep -i *.log find . -print | xargs grep -i "*.log" find . -print | xargs grep -i '*.log' does know right code?
thanks you
you don't need * @ all; doesn't useful here. in regex syntax (as used grep), * means "0 or more of preceding character". when there is no preceding character, syntax error.
by contrast, . in regex means "match single character". if want match period, need escape or put inside character class, so:
find . -exec grep -i -e '[.]log' -- /dev/null '{}' + if line needs end with .log, contrast, anchor match $:
find . -exec grep -i -e '[.]log$' -- /dev/null '{}' + notes:
*.logglob syntax.[.]log$equivalent pattern in regex (regular expression) syntax. these 2 different languages.find ... | xargs ...buggy (fails filenames containing spaces, quotes, literal backslashes, etc) unless-print0used infind, ,-0usedxargs. both of these non-posix extensions, it's better use posix-compliant-exec ... {} +action infindxargs behavior of running few subprocesses possible names given literally.- the
grep ... -- /dev/nullidiom services 2 purposes: passing/dev/nullensuresgrep's defaults uses when passed @ least 2 files, iffindinvoked particulargrepinstance single filename.--flag, contrast, ensures subsequent filenames treated names, not flags; it's not strictly necessary when usedfindin manner (as arguments preceded./, not potentially looking optional arguments), practice nonetheless.
Comments
Post a Comment