Artificial intelligent assistant

Search two or more strings in a file I've SQL files on my database server which is a unix box. I am trying to find out what are the *.sql files which use a particular column of a table. For eg the content of `my_dir/SALES_TERRITORY.sql` is Select segment1,segment2 from HZ_CUST_SITE_USES_ALL where territory_id = :p_territory_id; So , my requirement is when I run my command I should get all the files which have the combination of 'HZ_CUST_SITE_USES_ALL' and 'territory_id'. I did below by searching the internet but I am not getting the desired output. grep -i "HZ_CUST_SITE_USES_ALL\|TERRITORY_ID" * My expectation is that the above command will give me a result like this grep -i "HZ_CUST_SITE_USES_ALL\|TERRITORY_ID" my_dir/* SALES_TERRITORY.sql Any help is much appreciated. Regards,

Use grep as below to list only filenames ( **-l** ): ( " **-maxdepth 0** " is to check on only under my_dir and it will not check sub directories in it.If you want sub-directories also to be checked , just remove that )

If your filenames having spaces in that you can use as below:


find ./* -maxdepth 0 -type f -exec grep -qi "HZ_CUST_SITE_USES_ALL" {} \; -and -exec grep -li "TERRITORY_ID" {} \;


**Edited for Solaris:**


find ./* -prune -type f -exec /usr/xpg4/bin/grep -qi "HZ_CUST_SITE_USES_ALL" {} \; -a -exec /usr/xpg4/bin/grep -li "TERRITORY_ID" {} \;


If you are sure that you do NOT have any spaces in between filenames , you can use simple for loop as below :


for file in $(find my_dir/* -maxdepth 0 -type f)
do
grep -qi "HZ_CUST_SITE_USES_ALL" "$file" && grep -il "TERRITORY_ID" "$file";
done

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 737c6202063978662c570466be12b33b