LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-15-2011, 11:31 AM   #16
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213

Original Poster
Blog Entries: 2

Rep: Reputation: 26

Quote:
Originally Posted by David the H. View Post
Sorry then, I can't help you much if you aren't using bash or a related shell.
(You really should mention requirements like that when when you first post your question.)
I did not previously know that "which shell do I use" would be an issue. I would have never even thought of that being relevant until now.

Quote:
This page shows that csh-based shells apparently don't have any of the parameter substitutions that borne/korn shells do.

http://www.lagmonster.org/docs/shell.html

If you really need the portability, then I guess you're limited to sed and command substitution then. Unless some tsch expert comes along and says otherwise.
And I don't see how sed and command substitution can be used in the 'find' command. Argh.
 
Old 06-15-2011, 11:34 AM   #17
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Raveolution View Post
I did not previously know that "which shell do I use" would be an issue. It's hard to predict when something like that will become important.
It's almost always very important.

A shell is basically a programming language. Most of the commonly used stuff is the same, but each shell has different features and different syntax.

When talking about Linux, bash is usually assumed, since it's very powerful and is default on almost all Linux distros.
 
1 members found this post helpful.
Old 06-15-2011, 11:38 AM   #18
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213

Original Poster
Blog Entries: 2

Rep: Reputation: 26
Quote:
Originally Posted by MTK358 View Post
It's almost always very important.

A shell is basically a programming language. Most of the commonly used stuff is the same, but each shell has different features and different syntax.

When talking about Linux, bash is usually assumed, since it's very powerful and is default on almost all Linux distros.
Okay, I can accept that. The... unpleasantries... start with whatever is causing the inability to get find working with sed, and the long scripting that seems to be needed to get around it.
 
Old 06-15-2011, 11:47 AM   #19
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by Raveolution View Post
And I don't see how sed and command substitution can be used in the 'find' command.
To which statement to you refer in detail? Do you want to use the output of an sed command as parameter for a find?
 
Old 06-16-2011, 09:48 AM   #20
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I didn't mean to imply that you did anything wrong by not mentioning the shell. It was just an FYI for the next time. But yeah, it does affect what syntax is supported, as the others have pointed out. Also be sure to mention if you're on a non-linux platform, as the versions of the core utilities used in other unixes usually have fewer options than the gnu counterparts.


You likely can't use command substitution in the way you want here (in the find command's -exec option), because there's no simple way to correctly and reliably feed the parameters you want to the commands inside it.

The loop options given before are really your best bet; either that or write an external script or function to call on instead. Use find to feed in the filenames and let the loop/script/function handle everything else.


I did some snooping around the convert command though, and finally found a way to make it print out the filename with the converted ending.
Code:
find . -iname "*.png" -exec convert "{}" -set filename:namefmt '%d/%t.jpg' 'jpg:%[filename:namefmt]' \;
-set filename:namefmt defines a filename format with the alias "namefmt", and '%d/%t.jpg' is the format that you want: directorypath/basename.newext. (Don't try to use %e here, as that's the extension of the input file. I ended up overwriting the original in one test.)

Then 'jpg:%[filename:namefmt]' is the actual output file argument, using that pre-defined pattern. Since there's as yet no file ending that tells the command what format to output as, you have to use the alternate syntax of format:filename to specify it.

These are the pages that helped me to figure this out:
http://www.imagemagick.org/Usage/files/#save
http://www.imagemagick.org/script/escape.php

Last edited by David the H.; 06-16-2011 at 09:50 AM.
 
1 members found this post helpful.
Old 06-16-2011, 10:01 AM   #21
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213

Original Poster
Blog Entries: 2

Rep: Reputation: 26
David the H:

While I'm saddened that either command substitution doesn't work between find and sed (and maybe also other commands), or it is a mystery that will remain difficult to unravel, I am going to be spending a lot of time studying the solution you put forth. Many thanks for the links, too. That's going to be a major help!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting logic sushil.cool Linux - Newbie 3 03-04-2010 11:41 AM
LSI Logic / Symbios Logic 53c875 (rev 14) -> HP Storageworks 1/8 G2 gileravxr Linux - Hardware 0 07-21-2009 04:45 AM
Bash Scripting POSIX Class [[:alnum:]] giving wrong output livetoday Linux - Newbie 3 01-21-2008 11:56 PM
Wrong parsing of ls command in bash scripting itz2000 Programming 3 04-25-2007 10:23 AM
Scripting entries into mysql with logic spiffytech Linux - Software 1 01-16-2006 02:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:26 PM.

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