LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-26-2005, 10:34 AM   #1
drjones69
LQ Newbie
 
Registered: Apr 2005
Distribution: Gentoo
Posts: 12

Rep: Reputation: 0
Help sought with 'find -exec'


Hi all!

Just been pulling my hair out for too long now, so am giving in and asking for help..

Problem : Have a large directory tree of web templates, looking to create a set of jpg or png thumbnails of them.

Direction : am currently using something along the lines of ..

find /home/me/webtemplates/ -name index.html -exec khtml2png '{}' /home/me/thumbnails/.....

The end bit is where the problem arises - essentially I want to take full pathname (ie. {}) and convert it into name which is acceptable as a filename (ie. replace / with - or something similar). Any ideas/clues.

To save time, all the other parts work, the find will return all the paths, khtml2png works and if replace the output name with a fixed term it goes through and converts each file to thumbnail, just overwriting each time. But the main point is that the out files must be named to relate to the location of the source document.

Have now spent 5 hours tinkering with this, so any request I read the manual or google, please be more specific (ie. which man or which search time) as I've seen many searchs on the web have ended with a 'google it' recommendation and I'm feeling the urge to scream everytime I see it! ;-)

Thanks in advance for any help.

Regards,
Ryan
 
Old 04-26-2005, 02:52 PM   #2
Matt Collier
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 80

Rep: Reputation: 15
Would something like this be of any use?

find /home/me/webtemplates/ -name index.html | perl -ne'chomp; $old = $_; s/\./_/g; system("khtml2png $old $_")'

The major problem you're facing is copying a string, and then only changing one instance of it. There are plenty of tools for changing every instance of a string, tr, sed, xargs -i, but since you need to keep a hold of the original as well, you'd need to store it somewhere else while the translation is happening, and bash isn't too happy with evaluating find's {} inside of a `` (or similar).

It'd be pretty simple for Perl to do the entire job, rather than just the translation, but keeping the original find in place, and having perl just call khtml2png keeps things relatively simple to modify.
 
Old 04-27-2005, 04:02 AM   #3
drjones69
LQ Newbie
 
Registered: Apr 2005
Distribution: Gentoo
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks!

Thanks! Worked a treat, I think I had to swap s/\. for s\// - but I could it out from there :-) You've saved me from another few hours of hair pulling :-) [Can't paste exactly, as it's on my home machine]

I suspected that perl held the answer, but knew nothing about it, I'm already looking forward to playing around with it some more :-)

Regards,
Ryan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I execute two commands on exec of a find? eantoranz Programming 3 08-03-2010 04:51 PM
find: missing argument to `-exec' pavodive Linux - Newbie 4 10-05-2009 02:24 PM
find /folder/* -exec ./file '{}' -nohomedir \; ??? utw-mephisto Linux - General 2 05-10-2005 08:09 AM
find -exec question eantoranz Linux - General 1 06-26-2004 10:57 AM
find -exec cricbk Linux - Newbie 4 01-05-2004 07:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration