Fedora Linux Support Community & Resources Center
  #1  
Old 28th December 2004, 07:02 AM
leaded Offline
Registered User
 
Join Date: May 2004
Posts: 373
Question Bash help: Find first n characters in a string?

I checked out the Advanced Bash Guide but I couldn't find what I need.

I need to get the first 2 digits of a string and store to a variable, and then I need the 4th and on to another. There's a function in VB.NET (I know, super lame, I took a class in it tho) that does it and it's like Microsoft.VisualBasic.Left("String",3) and it returns "Srt" or something.

Here's my practical use: I'm trying to convert all of my iTunes AAC files to MP3s so I can use them in my car. So far, I've figured out how to convert all of the files to MP3...
Code:
for i in *.m4a; do faad -w "$i" | lame - "`basename "$i" '.m4a'`.mp3"; done
Problem is, I'd like to also create ID3 tags automatically. With the filename alone, I can get the track number and song title, because each file is like "03 Melissa.m4a". I can remove the .m4a by using $basename "$i" '.m4a' but that still leaves the "03 " in front.

I ultimately want it to be for i in *.m4a; do faad -w "$i" | lame --tt "Track Title" --tn TrackNumber - "`basename "$i" '.m4a'`.mp3"; done but I don't know what kind of text manipulation it would take to achieve this.

Any help would be MUCH appreciated!!!! Thanks!!!!

-Alan
Reply With Quote
  #2  
Old 28th December 2004, 07:09 AM
leaded Offline
Registered User
 
Join Date: May 2004
Posts: 373
Should I be trying something other than bash? This doesn't sound too advanced, but I don't know enough of the other languages to whip something up. I know SOME perl and SOME php, but I don't know how to run anything similar to the for, done thing in either language. This doesn't seem too difficult so I little shove in the right direction would be great!
Reply With Quote
  #3  
Old 29th December 2004, 12:16 AM
Jman Offline
Registered User
 
Join Date: Mar 2004
Location: Minnesota, USA
Age: 28
Posts: 7,909
You probably want to put this in a script instead of one long line, as it may get complicated. That guide shows how.

Read the string manipulation part of the bash guide, substring extraction especially.

You can get the substring of the number and then the title, store them in variables, then use them in the command. For example:

Code:
FILE=`basename "$i" '.m4a'`
TRACKNUM=${FILE:0:2}
TRACKNAME=${FILE:3}
I think this will work but I have not tried it. And then you can execute your command, but with these variables.
Reply With Quote
  #4  
Old 29th December 2004, 05:53 PM
leaded Offline
Registered User
 
Join Date: May 2004
Posts: 373
Thanks, I didn't know what to even call it... subtraction, now I know. I was thinking crop or something but I knew that couldn't be right.

Thanks again!
Reply With Quote
Reply

Tags
bash, characters, string

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeking to understand string operator := Bash 101 troyatlarge Programming & Packaging 4 4th August 2009 03:16 PM
Adding \n newline control character onto a bash string CD-RW Programming & Packaging 4 2nd July 2009 11:49 AM
sed regex string replacement after match string issue adosch Using Fedora 10 29th June 2007 04:07 PM
Problem when quoting special characters in bash poker Using Fedora 4 8th January 2006 09:06 AM
A couple of BASH scripts people might find useful mugga Programming & Packaging 0 26th October 2004 01:25 PM


Current GMT-time: 11:51 (Tuesday, 30-09-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat