Using Mac terminal server linux/bash commands, how can I search for a particular text string in all *.txt files in the current folder plus all files in the subfolders inside the current folder?
Asked
Active
Viewed 982 times
-2
-
2Please avoid *"Give me the codez"* questions that have been asked and answered so many times you have to make an effort to avoid finding an answer. Instead show the script you are working on and state where the problem is. Also see [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/608639) – jww Jul 06 '18 at 14:55
2 Answers
0
grep -i "xxx" */*
xxx
is the target text I am trying to find.

double-beep
- 5,031
- 17
- 33
- 41

J-Ko
- 2,503
- 3
- 9
- 6
-
1Answer misses the look in .txt files only requirement and starting from current dir and below. – Fred Gannett Jul 06 '18 at 15:11
-1
find . -type f -print | egrep ".txt$" | xargs grep "SearchPatern"
Explained as Find all the file names in the current directory and below send to ....
grep which picks out the file name that end in .txt and send names to ....
xargs which will execute a grep command on each file to look for SearchPatern.

Fred Gannett
- 111
- 1
- 4