From: Atropo on 2 Jul 2010 17:47 On 2 jul, 17:30, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: > Atropo <lxvasq...(a)gmail.com> writes: > > I took this script suggested by Stephane CHAZELAS > > > find . -name "* .txt" -exec sh -c 'file=$1; exec mv "${file}" "${file > > % .txt}.txt"' {} {} \; > > I think some stray spaces have crept in there in addition to the newline > which is at least obvious. > > > this was intended to rename files, but i want create new files with > > same name but another extension. > > > find . -type f -name PPpldate.jpg -exec sh -c 'file=$1; -exec touch "$ > > {file%.*}.png"' {} {} \; > > > ./tmp/PPpldate.pl: bad substitution > > Hmm. There is some evidence that this is not what you typed. Please > use some cut and paste method so that you post exactly what was > entered. > > > I guess is the last two {}, but not sure, not enough documentation. > > No, they are fine. > > I'd do this: > > find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} \; > > but please test it first by replacing touch with something like echo. > > -- > Ben. Thanks Ben. i ran your suggestion and throws same errors find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} \; ../tmp/PPpldate.jpg: bad substitution ../tmp/PPpldate2.jpg: bad substitution only works if I take off the %.* , could be that it's specific for ksh ? and i am calling sh
From: Chris F.A. Johnson on 2 Jul 2010 17:49 On 2010-07-02, Atropo wrote: > On 2 jul, 17:30, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: >> Atropo <lxvasq...(a)gmail.com> writes: >> > I took this script suggested by Stephane CHAZELAS >> >> > find . -name "* .txt" -exec sh -c 'file=$1; exec mv "${file}" "${file >> > % .txt}.txt"' {} {} \; >> >> I think some stray spaces have crept in there in addition to the newline >> which is at least obvious. >> >> > this was intended to rename files, ?but i want create new files with >> > same name but another extension. >> >> > find . -type f -name PPpldate.jpg -exec sh -c ?'file=$1; -exec touch "$ >> > {file%.*}.png"' {} {} \; >> >> > ./tmp/PPpldate.pl: bad substitution >> >> Hmm. ?There is some evidence that this is not what you typed. ?Please >> use some cut and paste method so that you post exactly what was >> entered. >> >> > I guess is the last two ?{}, but not sure, not enough documentation. >> >> No, they are fine. >> >> I'd do this: >> >> ? find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} \; >> >> but please test it first by replacing touch with something like echo. >> >> -- >> Ben. > > Thanks Ben. > > i ran your suggestion and throws same errors > > find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} > \; > ./tmp/PPpldate.jpg: bad substitution > ./tmp/PPpldate2.jpg: bad substitution > > only works if I take off the %.* , could be that it's specific for > ksh ? and i am calling sh It will work in any POSIX shell. Presumably, your sh is not a standard shell. -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
From: Atropo on 2 Jul 2010 19:05 On 2 jul, 17:49, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: > On 2010-07-02, Atropo wrote: > > On 2 jul, 17:30, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: > >> Atropo <lxvasq...(a)gmail.com> writes: > >> > I took this script suggested by Stephane CHAZELAS > > >> > find . -name "* .txt" -exec sh -c 'file=$1; exec mv "${file}" "${file > >> > % .txt}.txt"' {} {} \; > > >> I think some stray spaces have crept in there in addition to the newline > >> which is at least obvious. > > >> > this was intended to rename files, ?but i want create new files with > >> > same name but another extension. > > >> > find . -type f -name PPpldate.jpg -exec sh -c ?'file=$1; -exec touch "$ > >> > {file%.*}.png"' {} {} \; > > >> > ./tmp/PPpldate.pl: bad substitution > > >> Hmm. ?There is some evidence that this is not what you typed. ?Please > >> use some cut and paste method so that you post exactly what was > >> entered. > > >> > I guess is the last two ?{}, but not sure, not enough documentation. > > >> No, they are fine. > > >> I'd do this: > > >> ? find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} \; > > >> but please test it first by replacing touch with something like echo. > > >> -- > >> Ben. > > > Thanks Ben. > > > i ran your suggestion and throws same errors > > > find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} > > \; > > ./tmp/PPpldate.jpg: bad substitution > > ./tmp/PPpldate2.jpg: bad substitution > > > only works if I take off the %.* , could be that it's specific for > > ksh ? and i am calling sh > > It will work in any POSIX shell. Presumably, your sh is not a > standard shell. > > -- > Chris F.A. Johnson, author <http://shell.cfajohnson.com/> > =================================================================== > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) > Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Thanks Chris. how could i know if it's standard?? SunOS <machine_name> 5.10 Generic_127127-11 sun4v sparc SUNW,Sun-Fire- T200 I'm interest in using find because it works with the entire path/ filename. how can i accomplish this.. i mean create a new file with the same name but another extension?
From: Ben Bacarisse on 2 Jul 2010 19:36 Atropo <lxvasquez(a)gmail.com> writes: > On 2 jul, 17:49, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: >> On 2010-07-02, Atropo wrote: >> > On 2 jul, 17:30, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: <snip> >> >> -- >> >> Ben. It's better to not quote sig bocks. >> > i ran your suggestion and throws same errors >> >> > find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} >> > \; >> > ./tmp/PPpldate.jpg: bad substitution >> > ./tmp/PPpldate2.jpg: bad substitution >> >> > only works if I take off the %.* , could be that it's specific for >> > ksh ? and i am calling sh >> >> It will work in any POSIX shell. Presumably, your sh is not a >> standard shell. <snip> > how could i know if it's standard?? > SunOS <machine_name> 5.10 Generic_127127-11 sun4v sparc SUNW,Sun-Fire- > T200 What matters is what shell is invoked when sh is executed by find. That is not always easy for a beginner to determine, and I can't tell from your system's descrition. The command "which sh" will tell you the file that is being executed and ls -l $(which sh) will show you if this is a symbolic link, but that might not tell you much. What does this do: f=x.jpg; echo ${f%.*} ? If you don't get "x" as the output then there is something non-standard about your shell. If you can't use % substitutions, then I think this will work but I may have got the quoting wrong: find . -type f -name \*.jpg -exec sh -c \ 'touch "$(dirname """$1""")/$(basename """$1""" .jpg).png"' {} {} \; (The quoting can be simpler if you are sure you don't have any spaces or other problem characters in the file names.) <snip> -- Ben.
From: Jon LaBadie on 3 Jul 2010 10:59 Atropo wrote: > On 2 jul, 17:30, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: >> Atropo <lxvasq...(a)gmail.com> writes: >>> I took this script suggested by Stephane CHAZELAS >>> find . -name "* .txt" -exec sh -c 'file=$1; exec mv "${file}" "${file >>> % .txt}.txt"' {} {} \; >> I think some stray spaces have crept in there in addition to the newline >> which is at least obvious. >> >>> this was intended to rename files, but i want create new files with >>> same name but another extension. >>> find . -type f -name PPpldate.jpg -exec sh -c 'file=$1; -exec touch "$ >>> {file%.*}.png"' {} {} \; >>> ./tmp/PPpldate.pl: bad substitution >> Hmm. There is some evidence that this is not what you typed. Please >> use some cut and paste method so that you post exactly what was >> entered. >> >>> I guess is the last two {}, but not sure, not enough documentation. >> No, they are fine. >> >> I'd do this: >> >> find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} \; >> >> but please test it first by replacing touch with something like echo. >> >> -- >> Ben. > > Thanks Ben. > > i ran your suggestion and throws same errors > > find . -type f -name \*.jpg -exec sh -c 'touch "${1%.*}.png"' {} {} > \; > ./tmp/PPpldate.jpg: bad substitution > ./tmp/PPpldate2.jpg: bad substitution > > only works if I take off the %.* , could be that it's specific for > ksh ? and i am calling sh > Your Solaris /bin/sh does not implement %.*. Replace "sh -c" with "ksh -c"
|
Next
|
Last
Pages: 1 2 Prev: newbie: using find to touch new files Next: Two copies of one input stream |