Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 30 Aug 2014, 16:43
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Looking for Bash script to text search wildcard PDF's
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
Semme

Joined: 07 Aug 2011
Posts: 3777
Location: World_Hub

PostPosted: Sat 09 Mar 2013, 10:22    Post_subject:  Looking for Bash script to text search wildcard PDF's
Sub_title: And please >> leave the title intact!
 

Very Happy Greetings!

I'd like to have this modified to:
    1) Open a shell.

    2) Ask for a path

    3) Ask for a pattern.

    4) Results to stdout.

I'm not after a Gtk window as I'd prefer to keep the mouse quiet.

If easy enough and you have the time, I'd love a walk-through.

Thanks.
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1063

PostPosted: Sat 09 Mar 2013, 17:54    Post_subject:  

Hey Semme

You mean something (simple) like this?
Code:
#!/bin/bash
tail -n +5 "$0" > /tmp/pdfgrepcli            # Copy itself, except first 4 lines, to /tmp/pdfgrepcli
exec xterm -hold -e bash /tmp/pdfgrepcli      # open terminal and execute /tmp/pdfgrepcli
# -----------------------------------------------------------------------------
[ ! `which pdfgrep` ] && echo "Install 'pdfgrep' first, exiting..." && exit 1

read -p "Path: " PDFPATH
read -p "Pattern: " PATTERN

find "$PDFPATH" -type f -iname "*.pdf" -exec pdfgrep "$PATTERN" {} +

Regading no.1: if I understood correctly - you want to open terminal window when the script is clicked, right?
If not, just comment out or delete 2nd & 3rd line (tail... & exec...).

BTW: From the link you have posted there - Puppy (at least Slacko) has also 'pdftotext' and in combination with 'grep --color=always' it looks quite nice; check it out. Wink
Code:
pdftotext /usr/share/examples/ps-pdf/Acrobat.pdf - | grep --color=always "document"

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
Semme

Joined: 07 Aug 2011
Posts: 3777
Location: World_Hub

PostPosted: Sun 10 Mar 2013, 16:53    Post_subject:  

AWESOME! Works a treat SFR. Cool

Is tail -n +5 "$0" > /tmp/pdfgrepcli setup as a buffer to store input while waiting for further instruction?

OK.. xterm >> retain window, have bash execute (code I have yet to understand):
Code:
[ ! `which pdfgrep` ] && echo "Install 'pdfgrep' first, exiting..." && exit 1

read -p "Path: " PDFPATH
read -p "Pattern: " PATTERN

find "$PDFPATH" -type f -iname "*.pdf" -exec pdfgrep "$PATTERN" {} +

The rest is gonna take me time to study and digest.

A little Bash know-how coupled with regx, right?
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1063

PostPosted: Mon 11 Mar 2013, 10:03    Post_subject:  

Hey Semme

Glad it works. Smile
Quote:
Is tail -n +5 "$0" > /tmp/pdfgrepcli setup as a buffer to store input while waiting for further instruction?

This is one of the first tricks I have learned. Cool
It's kinda "self-extracting" routine - basically this line copies the script itself (its path is in $0), except first 4 lines, to tempfile and then, in order to open terminal window, redirects execution (let's say - jumps) to this file using 'exec xterm...'

Next line is to ensure that 'pdfgrep' is really available (which pdfgrep), then 'read' to get user's input and finally the line you have delivered, however I never use 'find ... -exec'
Code:
-exec pdfgrep "$PATTERN" {} +

so honestly I don't fully understand that syntax. Rolling Eyes

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0494s ][ Queries: 12 (0.0031s) ][ GZIP on ]