-   Linux - Software (
-   -   String manipulation in bash (

dalmat 12-03-2007 12:33 PM

String manipulation in bash
I'm trying to make a bash script for nautilus that converts a flv-file to mpg. I can't rename the new file properly. The file name.flv should be called name.mpg when converted. Pretty simple. The basic idea is this:



#triple backspace to delete flv-ending in filename

ffmpeg -i "$1" "$1""$b"mpg

"$1": is input filename
"$1""$b"mpg: is output filename

I've tried many different versions of this, but the best of them only converts to a filename where the backspace characters are reckognized as some weird symbol. How do I manipulate the string properly?

nx5000 12-03-2007 12:42 PM


man bash

ah not the good variable, this is one correct answer:

ffmpeg -i "$1" ${1/flv/mpeg}

druuna 12-03-2007 12:47 PM


Something like this should work: ${1%%.flv}.mpg

ffmpeg -i "$1" ${1%%.flv}.mpg (i did not check to see if the quotes are needed).

This uses bash' parameter expansion (see manpage for more details).

Hope this helps.

dalmat 12-03-2007 01:21 PM

Thanks. Both suggestions work.

hellork 12-03-2007 06:50 PM

There is also

for x in *flv; do ffmpeg -i "$x" "${x/.flv/.mpg}";done

If you have a big job to do and want to take lunch early.

All times are GMT -5. The time now is 02:40 PM.