Reputation: 27
I am trying to read records from file and if string is available in any files then print that file. code:
while read line
do
find ./q/q*.q -type f -exec grep -ls $line {} +
donr< "file_name"
file_name have data like:
india
usa_k
in_va
while execution i am getting grep: illegal option error
Same time I want to store o/p of find in variable. Any help
in loop only i want to concate $line and find o/p and direct in txt file.
code some like:
$line | o/p find >> missing.txt
In i/p file if we have value "INDIA" if this value is aviable in other txt file then i want to print "india is aviable in (filename)" and store this information in txt file. this we need to do for all values..
Upvotes: 1
Views: 1703
Reputation: 295716
Put --
before your names as an end-of-option terminator, -e
before the expansion of "$line"
, and quote that expansion. This prevents either the names or the search string from being read as options.
while IFS= read -r line; do
find ./q/q*.q -type f -exec grep -l -e "$line" -- {} + |
while IFS= read -r matched_file; do
echo "$line is available in $matched_file"
done
done <file_name >results.txt
Upvotes: 1