find -exec text replace
I have file
file1.jpg file2.jpg in /var/foo For me to switch from jpg to png I would in a for loop Code:
for i in *jpg; do convert "$i" "${ijpg}png"; done here's my attempt (doesn't work) Code:
find /dir -iname \*jpg -exec convert {} ${{}jpg}png \; I want it to find every *jpg file, and substitute {} with convert file1.jpg file1.png (etc) |
Me, I'd write a shell script containing your line above, and exec that.
conv.sh Code:
#!/bin/bash Code:
find /dir -iname \*.jpg -exec conv.sh {} \; |
Thanks for the idea goumba. That could be useful for more expansive scripts running on each file
I recalled what I did (maybe this will be useful for whoever stumbles here) If I wanted to convert a bunch of *jpgs to png and then rename in a single find command Code:
find /dir/to/jpgs/ -iname \*jpg -execdir convert {} {}.png \; -execdir rename 's/jpg\.png/png/' {}.png \; foo.jpg -> foo.jpg.png (a png file) -> foo.png |
Quote:
Code:
"${i/jpg/png}" Code:
$ i=file.jpg |
suicidaleggroll, I found it odd too, but I noticed even in code tags, that the forum will mangle certain character sequences (learned this in a recent bash thread), so I ignored it, but good thing that you did indeed point out the OPs error.
|
The forum does strip out the first % symbol in a post, regardless if it's in code tags. Maybe there was one in his post that got ripped out? (Note: I had to put two % symbols in up there to get the one to come through).
|
It is possible. I don't want to drag this too far off-topic, but fyi it also does the same for backslash.
|
Ahh... yes. That's weird. I do use the percent symbol there. It looks like it got ripped out and makes it look like a very non-valid command. forum limitation I believe..
a $i followed by a percent symbol is used to strip out characters and then add in the correct png to make convert file.jpg file.png I have noticed the percent symbol being stripped, even doubles since I'll edit the post and it'll go away too. Very annoying behavior for code tags e.g. Code:
"${i%%jpg}png" |
All times are GMT -5. The time now is 06:25 AM. |