From: Atropo on 3 Dec 2009 13:13 Hi all, a find command feeds me with filenames and I want to touch those filenames stripping the extension and giving new one. i know i can with variable ${filename%.*} have the filename without extension but don't know how to implement on xargs. find | awk '{print $9}' | xargs -I 'nww' cp -p nww nww%.*.HDR or find | awk '{print $9}' | echo xargs -I 'nww' cp -p nww ${nww%.*}.HDR as you can imagine none of both works. how could i do this on the fly ( i mean without create a heredocument)
From: Rakesh Sharma on 4 Dec 2009 07:16 On Dec 3, 11:13 pm, Atropo <lxvasq...(a)gmail.com> wrote: > Hi all, > > a find command feeds me with filenames and I want to touch those > filenames stripping the extension and giving new one. > > i know i can with variable ${filename%.*} have the filename without > extension but don't know how to implement on xargs. > > find | awk '{print $9}' | xargs -I 'nww' cp -p nww nww%.*.HDR > > or > > find | awk '{print $9}' | echo xargs -I 'nww' cp -p nww ${nww%.*}.HDR > > as you can imagine none of both works. how could i do this on the fly > ( i mean without create a heredocument) This is one way to do it: find . -type f \( -name '*.*' -o -name '.*.*' \) -exec csh -c 'if ( \! -e $1:r:q || -f $1:r:q ) cp -pf $1:q $1:r:q' {} {} \; Meaning: find all regular files in your directory tree of interest, then amongst those files look for that have an extension, ensure that the filename minus the extenstion doesn't already exist or if does, then ensure that it's a regular file (since otherwise the copy operation would be a problem). Finally, when all these conditions are met, then trigger the copy command 'cp' with the -f/-p options so that the copy opeartion happens to be forceful with no warnings being generated. --Rakesh
From: WANG Cong on 6 Dec 2009 03:00 On 12/04/09 02:13, Atropo <lxvasquez(a)gmail.com> wrote: > Hi all, > > a find command feeds me with filenames and I want to touch those > filenames stripping the extension and giving new one. > > i know i can with variable ${filename%.*} have the filename without > extension but don't know how to implement on xargs. > > find | awk '{print $9}' | xargs -I 'nww' cp -p nww nww%.*.HDR > > or > > find | awk '{print $9}' | echo xargs -I 'nww' cp -p nww ${nww%.*}.HDR > > as you can imagine none of both works. how could i do this on the fly > ( i mean without create a heredocument) You can use rename(1), in this case it should be used like this: find . -name '*.*' -print0 | xargs -0 echo mv '{}' '{}.HDR' | sed -e 's/\..*\.HDR$/\.HDR/' | sh Totoally untested. :) Note, you need to be careful, if there are files like 'foo.a', 'foo.b', you will only get one 'foo.HDR'. -- Live like a child, think like the god.
From: WANG Cong on 6 Dec 2009 03:01 On 12/06/09 16:00, WANG Cong <xiyou.wangcong(a)gmail.com> wrote: > On 12/04/09 02:13, Atropo <lxvasquez(a)gmail.com> wrote: > >> Hi all, >> >> a find command feeds me with filenames and I want to touch those >> filenames stripping the extension and giving new one. >> >> i know i can with variable ${filename%.*} have the filename without >> extension but don't know how to implement on xargs. >> >> find | awk '{print $9}' | xargs -I 'nww' cp -p nww nww%.*.HDR >> >> or >> >> find | awk '{print $9}' | echo xargs -I 'nww' cp -p nww ${nww%.*}.HDR >> >> as you can imagine none of both works. how could i do this on the fly >> ( i mean without create a heredocument) > > You can use rename(1), in this case it should be used like this: Oops, finally I used 'mv', not 'rename', so ignore this line. :) > > find . -name '*.*' -print0 | xargs -0 echo mv '{}' '{}.HDR' > | sed -e 's/\..*\.HDR$/\.HDR/' | sh > > Totoally untested. :) > > Note, you need to be careful, if there are files like > 'foo.a', 'foo.b', you will only get one 'foo.HDR'. -- Live like a child, think like the god.
From: WANG Cong on 6 Dec 2009 03:10
On 12/06/09 16:01, WANG Cong <xiyou.wangcong(a)gmail.com> wrote: > On 12/06/09 16:00, WANG Cong <xiyou.wangcong(a)gmail.com> wrote: > >> On 12/04/09 02:13, Atropo <lxvasquez(a)gmail.com> wrote: >> >>> Hi all, >>> >>> a find command feeds me with filenames and I want to touch those >>> filenames stripping the extension and giving new one. >>> >>> i know i can with variable ${filename%.*} have the filename without >>> extension but don't know how to implement on xargs. >>> >>> find | awk '{print $9}' | xargs -I 'nww' cp -p nww nww%.*.HDR >>> >>> or >>> >>> find | awk '{print $9}' | echo xargs -I 'nww' cp -p nww ${nww%.*}.HDR >>> >>> as you can imagine none of both works. how could i do this on the fly >>> ( i mean without create a heredocument) >> >> You can use rename(1), in this case it should be used like this: > > > Oops, finally I used 'mv', not 'rename', so ignore this line. :) > > >> >> find . -name '*.*' -print0 | xargs -0 echo mv '{}' '{}.HDR' >> | sed -e 's/\..*\.HDR$/\.HDR/' | sh >> >> Totoally untested. :) Use this one: find your_dir -name '*.* '-print0 | xargs -0 -I foo echo mv 'foo' 'foo.HDR' | sed -e 's/\(.*\)\..*\.HDR$/\1\.HDR/g' | sh -- Live like a child, think like the god. |