I have file1.txt with string values such asNew Drug ApplicationDrug ProductDosing instructionsI need to count how often these strings occur in file2.txt with data such asRegulatory New Drug Application for Drug Product after testing of Dosing instructions for all new studies.The commands I have used are;foreach string ( `cat terms.txt` )foreach? echo $string >>out.txtforeach? grep $string data.txt | wc >>out.txtendThe out.txt will not return the complete string with spaces. Instead it returns data such as:The -1New -2Application -1etc.I have tried adding quotes and forward slashes to the terms in my data files, egrep, fgrep - to no avail. How do I get the data I want from these two files?
Find strings in file1, count occurrences in file2
shell script;search;string