You are not logged in.

#1 2009-10-10 14:36:24

PingPing
Member
From: /dev/null
Registered: 2009-07-24
Posts: 39
Website

[Solved] Need help with a basic shell scripting query using 'sed'.

I've never used sed before but my problem is this:

1.  I have about 40+ files all with the extension .flv.mp3 in a directory.
2.  I want to change the extension from .flv.mp3 to just .mp3.

What's the best way of doing this?

Last edited by PingPing (2009-10-10 15:30:53)

Offline

#2 2009-10-10 14:38:25

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Need help with a basic shell scripting query using 'sed'.

man rename

Offline

#3 2009-10-10 15:08:43

quarkup
Member
From: Portugal
Registered: 2008-09-07
Posts: 497
Website

Re: [Solved] Need help with a basic shell scripting query using 'sed'.

rename .flv.mp3 .mp3 *.flv.mp3

and it may be solved.


but using sed is a bit different but very possible.

you can create a script with a loop (for/while).

for all of those files, u just need to do this:


#! /bin/bash
# by quarkup™

for filename in `ls *.flv.mp3`
   do
    target_name = `echo $filename | sed -e 's|\.flv\.mp3$|\.mp3|g'`
    mv $filename $target_name
  done

return 0

quite simple
big_smile


anyway, you got the package "file-rename-utils" in the AUR which provides you the "mv_sed" executable (script) and another ones which may help you on another times.

Last edited by quarkup (2009-10-10 15:15:10)


If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.

Offline

#4 2009-10-10 15:18:21

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: [Solved] Need help with a basic shell scripting query using 'sed'.

or in bash-isms only:

#!/bin/bash
for file in *.flv.mp3; do
    mv "$file" "${file%.mp3}"
done

Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#5 2009-10-10 15:30:30

PingPing
Member
From: /dev/null
Registered: 2009-07-24
Posts: 39
Website

Re: [Solved] Need help with a basic shell scripting query using 'sed'.

Thanks very much everyone.  I went for the simplest option:

rename 's/flv\.mp3/mp3/' *.flv.mp3

but many thanks for the shell scripting advice.  I'm sure I'll have cause to use it in the future. smile

Offline

Board footer

Powered by FluxBB