On 24/11/11 14:43, Chris Walker wrote:
An example of a file is this :- lamborghini miura_1024.jpg,c85 and so there, I'd like to remove the ,c85. But a bigger problem is where I have the odd file which has a numeric extensions such as .;1 and that's where I struggle. How do I do a substitution in my script to cope with things like that?
I came up with something like this (please only work on a backup set of images!)
Use "find" to find files matching <something>.jpg.<something>: $ find . -name '*.jpg.*' ./x y.jpg.;1
For each one, create the command mv "<something>.jpg.<something>" "<something>.jpg" $ find . -name '*.jpg.*' | sed -r 's/^(.*.jpg)..*$/mv "\0" "\1"/' mv "./x y.jpg.;1" "./x y.jpg"
Pipe the commands through Bash to run them. $ find . -name '*.jpg.*' | sed -r 's/^(.*.jpg)..*$/mv "\0" "\1"/' | bash
If in doubt, just use it to create a script: $ find . -name '*.jpg.*' | sed -r 's/^(.*.jpg)..*$/mv "\0" "\1"/' > myscript.sh .. and then sanity check the script before running it.