Reputation: 6653
I am trying to find a string across all log files and list those filenames.
And these log files are in sub-directories and these files are compressed with gz so using zgrep.
I am using below command
zgrep -lFR --include=Std_20170101* "ReceiveData: Receive call failed" /logs/nas/App02/201612* >> zfileslist
I am using --include=Std_20170101* are the files names in all subdirectories after App02 location . so to save time using above context.
I am sure that we have entries in those dates log files but some how its not showing them.
Please help.
Upvotes: 0
Views: 511
Reputation: 43039
Use --include-dir
option since --include
is restricted to only files:
zgrep -lFR --include-dir="Std_20170101*" "ReceiveData: Receive call failed" /logs/nas/App02/201612* >> zfileslist
From grep
man page:
**--include** If specified, only files matching the given filename pattern are searched. Note that --exclude patterns take priority over --include patterns. Patterns are matched to the full path specified, not only to the filename component. **--include-dir** If -R is specified, only directories matching the given filename pattern are searched. Note that --exclude-dir patterns take priority over --include-dir patterns.
Upvotes: 1
Reputation: 2167
If you want to give pattern then use find with -exec option and run grep on the files returned.
find ./ -name "*.dat" -exec grep "find pattern" {} \;
Upvotes: 0