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 Mon 20 Oct 2014, 06:16
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 [4 Posts]  
Author Message
Semme

Joined: 07 Aug 2011
Posts: 3965
Location: World_Hub

PostPosted: Sat 09 Mar 2013, 10:22    Post subject:  Looking for Bash script to text search wildcard PDF's
Subject description: 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: 1077

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: 3965
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: 1077

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 from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


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