The time now is Wed 25 Apr 2018, 20:25
All times are UTC - 4 |
Author |
Message |
Semme

Joined: 07 Aug 2011 Posts: 7827 Location: World_Hub
|
Posted: 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! |
|
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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 1655
|
Posted: 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.
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
|
|
 |
Semme

Joined: 07 Aug 2011 Posts: 7827 Location: World_Hub
|
Posted: Sun 10 Mar 2013, 16:53 Post subject:
|
|
AWESOME! Works a treat SFR.
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
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 1655
|
Posted: Mon 11 Mar 2013, 10:03 Post subject:
|
|
Hey Semme
Glad it works.
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.
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.
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
|
|
 |
|
|
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.0326s ][ Queries: 12 (0.0041s) ][ GZIP on ] |