Page 1 of 1
Help required from awk/sed boffins
Posted: 10 Sep 2011, 14:59
by Cheeseboy
Hi all,
I bought a media player for my sister. It does not agree with the .img file extension. It has to be .iso for it to work.
I did this:
Code: Select all
find . -iname '*.img' -exec mv {} {}.iso \;
It works, but it is not neat. I do not like my files having the extension .img.iso...
I have seen some fancy sed stuff here lately, mainly by gordon, I think (I might be wrong, one of the new guys)
Anyone happy to give me some pointers?
Many thanks in advance!
Cheeseboy
Re: Help required from awk/sed buffins
Posted: 10 Sep 2011, 19:45
by 6feet5
Hi,
If you're trying to replace the '.img' extension, then try
Code: Select all
for file in `find . -iname '*.img'`; do mv $file ${file/.img/.iso}; done
/Johan
EDIT: Too tired to think. First try was way incorrect, second try misspelled. I'm going to bed now

Re: Help required from awk/sed buffins
Posted: 10 Sep 2011, 20:19
by carl
Re: Help required from awk/sed boffins
Posted: 10 Sep 2011, 23:29
by Cheeseboy
Thank you both!
Rename, eh? I never knew such a command existed. Why did I ever have to learn about mv in the first place?
EDIT:
To answer my own question: probably due to my Solaris background...
Re: Help required from awk/sed boffins
Posted: 11 Sep 2011, 00:54
by 6feet5
Hmm, rename was a new one to me as well.
I forgot to mention I usually echo the result to console, instead of execute them on the go. That way I get a chance of verifying I'm executing the command I had in mind (I know to well what damage a brain fart can do). So ,try
Code: Select all
for file in `find . -iname '*.img'`; do echo "mv $file ${file/.img/.iso}"; done
(or use rename command) Mark it, then paste it, and now you got no one to blame but yourself

.
/Johan
Re: Help required from awk/sed boffins
Posted: 11 Sep 2011, 01:11
by Cheeseboy
Hehe,
I usually use ls with the find -exec command before I commit myself as well

Re: Help required from awk/sed boffins
Posted: 11 Sep 2011, 02:46
by RandomUsername
Rename is a python command I believe (I.e. not native bash). It only works with regular expressions. You can't just do
Re: Help required from awk/sed boffins
Posted: 11 Sep 2011, 03:48
by Cheeseboy
I could not get any of the suggested solutions to work flawlessly.
rename did not seem to work at all as suggested.
Johan's little script worked, but for some reason missed 3 directories (perhaps because of spaces in directory/file names?)
Anyhoo, I tweaked the remaining stuff manually now, so all sorted.
Thanks again!