0

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"
1
  • No this not working ether , I have tested Commented Jun 14, 2018 at 4:06

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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"

2 Comments

I can see the echo output in output text file , problem is find result not writing to output file look like below . /Search_pdf.sh *******pdf******** - /static/pdf/pdf1.pdf\n *******pdf******** - /static/pdf/pdf1.pdf\n ./Search_pdf.sh *******pdf******** - /static/pdf/pdf2.pdf\n *******pdf******** - /static/pdf/pdf2.pdf\n ./Search_pdf.sh *******pdf******** - /static/pdf/pdf3.pdf\n *******pdf******** - /static/pdf/pdf3.pdf\n
also added the variables inside the double quotes as suggested on other comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.