LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-03-2007, 11:33 AM   #1
dalmat
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:

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

Rep: Reputation: 52
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}

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

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

Original Poster
Rep: Reputation: 0
Thanks. Both suggestions work.
 
Old 12-03-2007, 05:50 PM   #5
hellork
Member
 
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 05:57 PM.
 
  


Reply


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 06:45 PM
string manipulation in BASH ovince Programming 4 04-16-2007 07:15 PM
String manipulation Manuel Alvarado Linux - Newbie 2 09-06-2006 09:49 PM
String manipulation with BASH script King V Programming 9 04-21-2006 03:15 PM
bash + string manipulation dave bean Programming 7 02-16-2005 11:16 AM


All times are GMT -5. The time now is 07:04 AM.

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