On 24/11/11 15:31, Mark Rogers wrote:
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.
Fallen at the second hurdle!
I modified the find command slightly (see below)
find . -name '*.jpg;1' | sed 's/^(.*.jpg)..*$/mv "\0" "\1"/' sed: -e expression #1, char 31: invalid reference \1 on `s' command's RHS
The file in that directory is cover.jpg;1 and not jpg.;1 as I said above. Sorry if that's complicated things.
I've also just tried Brett's suggestion and that didn't return any errors but didn't do anything either :-(
The file I'm trying it with is a piccy I've just grabbed from my own folder as a test. That's test.jpg;1 but whatever I do, makes no difference.
For some reason, Thunderbird has decided to take ages connecting to my smtp server and hence replies are a bit delayed. That seems to be a consequence of doing the upgrade from Mandriva 2010 to 2011.