I need to know the complete file path when I grep
.
I use commands like
cat *.log | grep somethingtosearch
Now what I need to show the result with complete file path from where the matched result were taken out.
Help anyone?
If you want to find in all files of a directory, you can use grep -r /path/to/directory .
To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.
If you are using GNU grep, then you can use the following: grep -ir --include "*. cpp" "xyz" . The command above says to search recursively starting in current directory ignoring case on the pattern and to only search in files that match the glob pattern "*.
Display the file names that matches the pattern : We can just display the files that contains the given string/pattern. 4. Checking for the whole words in a file : By default, grep matches the given string/pattern even if it is found as a substring in a file. The -w option to grep makes it match only the whole words.
Assuming you have two log-files in:
cd to C: and use:
grep -r somethingtosearch temp/*.log
It will give you a list like:
temp/my.log:somethingtosearch temp/alsoMy.log:somethingtosearch1 temp/alsoMy.log:somethingtosearch2
I fall here when I was looking exactly for the same problem and maybe it can help other.
I think the real solution is:
cat *.log | grep -H somethingtosearch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With