bash script to find pattern in text file and return entire line

17,392

Within one dir

grep "search string" *.txt

Search or go to sub-dir

find /full/path/to/dir -name "*.txt" -exec grep "search string" {} ;\
Share:
17,392
Admin
Author by

Admin

Updated on June 13, 2022

Comments

  • Admin
    Admin almost 2 years

    I need to make a bash script which loops through a bunch of .txt files in a directory, then searches each .txt for a string, and returns the entire line that string appears on

    I know how to look through all the .txt files in the directory,

    I just need to be pointed in the right direction for searching the file itself, and returning a line based on a match in that line