chamara
chamara

Reputation: 1

Find command result, won't write to the output

I have below script, Need find all PDF associate pages in website . PDF_Search_File.txt content the URL of the PDF file

Example : /static/pdf/pdf1.pdf
          /static/pdf/pdf2.pdf 

But find result not writing to the output file.there is and issue below line

find . -type f -exec grep -l '$name' '{}' \; >>output_pdf_new.txt

Any information will help.

#!/bin/bash
filename="PDF_Search_File.txt"
while read -r line
do
        name="$line"
                echo "*******pdf******** - $name\n" >>output_pdf_new.txt
        find . -type f -exec grep -l '$name' '{}' \; >>output_pdf_new.txt
                echo "*******pdf******** - $name\n" >>output_pdf_new.txt
done < "$filename"

Upvotes: 0

Views: 145

Answers (2)

silveiralexf
silveiralexf

Reputation: 543

the problem is that since your redirecting the output to a file echo is not displaying the text, you can use tee -a to do both, for instance:

#!/bin/bash
filename="PDF_Search_File.txt"
while read -r line
do
        name="$line"
        echo "*******pdf******** - $name" | tee -a output_pdf_new.txt
        find . -type f -exec grep -l "$name" '{}' \; | tee -a output_pdf_new.txt
        echo "*******pdf******** - ${name}" | tee -a output_pdf_new.txt
done < "$filename"

Upvotes: 0

asatsi
asatsi

Reputation: 472

The variable $name should be in double quotes "$name" instead of single quotes. This is typical shell behaviour dealing with single and double quotes.

Upvotes: 1

Related Questions