using find to rename from 'name .ext' to 'name.ext'

using find to rename from 'name .ext' to 'name.ext'

Post by Chris Lot » Sat, 16 Dec 2006 08:04:16


I have many directories full of files that have a space before the
extension:
file .txt
file2 .txt
file3 .txt

I'm trying to use find and sed to rename them quckly to:
file.txt
file2.txt
file3.txt

Gleaned from the web I came up with osmething like this, but the names
are not fixed:
find . -name '* .mp3' -exec mv {} {} \; | sed 's/[:space:].txt$/.txt/'

is this close?
 
 
 

using find to rename from 'name .ext' to 'name.ext'

Post by Frank Terb » Sat, 16 Dec 2006 08:39:28

Chris Lott < XXXX@XXXXX.COM >:
[...]
[...]
[...]

How about:

[snip]
find . -name "* .txt" -exec \
sh -c 'file="{}"; mv "${file}" "${file% .txt}.txt"' \;
[snap]

Regards, Frank

--
There are no threads in alt.binaries.pictures. *** a,
so there's no gain in using a threaded news reader.
-- unknown source

 
 
 

using find to rename from 'name .ext' to 'name.ext'

Post by Stephane C » Sat, 16 Dec 2006 21:08:39

2006-12-15, 00:39(+01), Frank Terbeck:


find . -name "* .txt" -exec sh -c '
file=$1; exec mv "${file}" "${file% .txt}.txt"' {} {} \;

zmv '(**/)(*) (.txt)' '$1$2$3'

--
Sthane