LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   String manipulation in bash (http://www.linuxquestions.org/questions/linux-software-2/string-manipulation-in-bash-604164/)

dalmat 12-03-2007 11:33 AM

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:

Code:

#!/bin/bash

#triple backspace to delete flv-ending in filename
b="^H^H^H"

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 11:42 AM

Code:

b=${1/flv/mpeg}
man bash
substitution

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

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

druuna 12-03-2007 11:47 AM

Hi,

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 12:21 PM

Thanks. Both suggestions work.

hellork 12-03-2007 05: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 04:47 AM.