New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

Help required from awk/sed boffins

Got problems with your B2 or B3? Share and get helped!
Post Reply
Cheeseboy
Posts: 789
Joined: 08 Apr 2007, 12:16

Help required from awk/sed boffins

Post 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
Last edited by Cheeseboy on 10 Sep 2011, 23:27, edited 1 time in total.
6feet5
Posts: 269
Joined: 13 Apr 2007, 17:32
Location: Gnesta, Sweden
Contact:

Re: Help required from awk/sed buffins

Post 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 :-)
carl
Posts: 474
Joined: 07 May 2008, 04:41

Re: Help required from awk/sed buffins

Post by carl »

You can use rename:

Code: Select all

rename 's/\.img$/.iso/' *.img
/Carl Fürstenberg, Excito Software Developer
http://www.excito.com
support@excito.com
Cheeseboy
Posts: 789
Joined: 08 Apr 2007, 12:16

Re: Help required from awk/sed boffins

Post 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...
6feet5
Posts: 269
Joined: 13 Apr 2007, 17:32
Location: Gnesta, Sweden
Contact:

Re: Help required from awk/sed boffins

Post 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
Cheeseboy
Posts: 789
Joined: 08 Apr 2007, 12:16

Re: Help required from awk/sed boffins

Post by Cheeseboy »

Hehe,

I usually use ls with the find -exec command before I commit myself as well :-)
RandomUsername
Posts: 904
Joined: 09 Oct 2009, 18:49

Re: Help required from awk/sed boffins

Post 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

Code: Select all

rename fileA fileB
Cheeseboy
Posts: 789
Joined: 08 Apr 2007, 12:16

Re: Help required from awk/sed boffins

Post 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!
Post Reply