[ACCEPTED]-bash script to find pattern in text file and return entire line-search

Accepted answer
Score: 11

Within one dir

grep "search string" *.txt

Search or go to sub-dir

find /full/path/to/dir -name "*.txt" -exec grep "search string" {} ;\


Score: 0

you can use a loop:

for i in $(find|grep .txt); do grep "search" "$i"; If you also want to 2 print the filename with each match, add 1 -H to grep

Score: 0

One slight addition. Add -n to return the 1 line.

      grep -rn "foo" *.txt 

See grep --help for more.

More Related questions