Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-03-2007, 12:33 PM   #1
LQ Newbie
Registered: Dec 2005
Posts: 14

Rep: Reputation: 0
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?
Old 12-03-2007, 12:42 PM   #2
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
man bash

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

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

Last edited by nx5000; 12-03-2007 at 12:52 PM.
Old 12-03-2007, 12:47 PM   #3
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390

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.
Old 12-03-2007, 01:21 PM   #4
LQ Newbie
Registered: Dec 2005
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks. Both suggestions work.
Old 12-03-2007, 06:50 PM   #5
Registered: Nov 2007
Posts: 41

Rep: Reputation: 15
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.

Last edited by hellork; 12-03-2007 at 06:57 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash string manipulation kpachopoulos Programming 3 06-17-2007 07:45 PM
string manipulation in BASH ovince Programming 4 04-16-2007 08:15 PM
String manipulation Manuel Alvarado Linux - Newbie 2 09-06-2006 10:49 PM
String manipulation with BASH script King V Programming 9 04-21-2006 04:15 PM
bash + string manipulation dave bean Programming 7 02-16-2005 12:16 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration