I have a directory with multiple levels of sub-directories. These sub-directories contain a combination of .avi, .txt and .csv files.
I want to be able to search through all the .csv files for a particular word. Right now I am using the following command: grep -r "word" *
This also searches through the .avi and .txt files. How do I limit the search to just .csv files?
Apologies if this question has been asked before, I was not able to find it.
The solution which worked for me was:
find . -type f -iname "*.csv" -print0 | xargs -0 grep "word"
Reference: https://unix.stackexchange.com/questions/42407/pipe-find-into-grep-v
Further, if you want to count the number of "words" in each .csv file, use: find . -type f -iname "*.csv" -print0 | xargs -0 grep -c "word"
If you want to count the total number of times "word" appears in all .csv files in a directory, use: find . -type f -iname "*.csv" -print0 | xargs -0 grep -o "word" * | wc -l
you can find all csv file and then grep only in founded files:
find <your directory path> -name "*.csv" -type f | xargs grep "word"
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