Search pdfs in command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search pdfs in command line
# 1  
Old 09-24-2012
Search pdfs in command line

Hi,

I'm trying to search for a particular phrase in a large number of PDFs in a particular directory.

What I've done so far only prints out the line, but I haven't been able to display in which file the phrase appears.

Code:
find . -name '*.pdf' -exec pdftotext {} - \; | grep "search phrase"

I've been told that this could be achieved using pdfgrep, but I don't have root access on this machine and it appears that I'm missing some libraries when I tried to install it, so would prefer if I'm able to do this using pdftotext. Many thanks!
# 2  
Old 09-24-2012
If you create a file named grepPDF containing:
Code:
#!/bin/ksh
for i in "$@"
do
        pdftotext "$i" - | grep 'search phrase' > grepPDF.$$ && \
                printf "\nFollowing lines are in %s:\n" "$i" && \
                cat grepPDF.$$
done
rm grepPDF.$$

and make it executable:
Code:
chmod +x grepPDF

and move it to a directory that is in your search path, then the find command:
Code:
find . -name '*.pdf' -exec grepPDF {} +

should do what you want.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 09-24-2012
Give a try..
Code:
find . -name '*.pdf' -type f | while read FILE
do
 pdftotext $FILE | grep -q "search phrase"
 [ $? -eq 0 ] && echo $FILE
done

This User Gave Thanks to clx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a multi-line shell command output and execute logic based on result

The following is a multi-line shell command example: $cargo build Compiling prawn v0.1.0 (/Users/ag/rust/prawn) error: failed to resolve: could not find `setup_panix` in `human_panic` --> src/main.rs:14:22 | 14 | human_panic::setup_panix!(); | ... (2 Replies)
Discussion started by: yogi
2 Replies

2. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies

3. Shell Programming and Scripting

Bash script monitor directory and subdirectories for new pdfs

I need bash script that monitor folders for new pdf files and create xml file for rss feed with newest files on the list. I have some script, but it reports errors. #!/bin/bash SYSDIR="/var/www/html/Intranet" HTTPLINK="http://TYPE.IP.ADDRESS.HERE/pdfs" FEEDTITLE="Najnoviji dokumenti na... (20 Replies)
Discussion started by: markus1981
20 Replies

4. Shell Programming and Scripting

Search: find current line, then search back

Hello. I want to find a line that has "new = 0" in it, then search back based on field $4 () in the current line, and find the first line that has field $4 and "last fetch" Grep or Awk preferred. Here is what the data looks like: 2013-12-12 12:10:30,117 TRACE last fetch: Thu Dec 12... (7 Replies)
Discussion started by: JimBurns
7 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

7. UNIX for Dummies Questions & Answers

How to search and replace a particular line in file with sed command

Hello, I have a file and in that, I want to search for a aprticular word and then replace another word in the same line with something else. Example: In file abc.txt, there is a line <host oa_var="s_hostname">test</host> I want to search with s_hostname text and then replace test with... (2 Replies)
Discussion started by: sshah1001
2 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. Shell Programming and Scripting

command to search for a wod in a line

Can some one help me in finding a "word" in a line ?? ex : line : = "You may choose an icon for your message " i want to search for the existance of the word "message" thanks sri (2 Replies)
Discussion started by: Srini75
2 Replies
Login or Register to Ask a Question