LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-15-2006, 09:51 PM   #1
crewblunts
Member
 
Registered: Jan 2004
Location: Connecticut, USA
Distribution: Slackware & Ubuntu
Posts: 53

Rep: Reputation: 15
remove part of string in bash script


I am writing this bash script and i need to remove part of a string

Code:
#!/bin/bash

allTracks="/var/www/music/xml/tracks/all.xml"
touch "$allTracks"
echo "<allTracks>" >"$allTracks"

artistFilename="/var/www/music/xml/artists/all.xml"
touch "$artistFilename"
echo "<artists>" >"$artistFilename"
for level1 in *
do
        echo "<artist Artist=\"$level1\" XMLLink=\"xml/artists/$level1.xml\"></artist>" >>"$artistFilename"
        albumFilename="/var/www/music/xml/artists/$level1.xml"
        touch "$albumFilename"
        echo "<artist>" >"$albumFilename"
        for level2 in "$level1"/*
        do
                echo "<album albumTitle=\"$level2\" XMLLink=\"xml/albums/$level2.xml\"></album>" >>"$albumFilename"

                if [ -d "$level2" ]
                then
                        if [ ! -e "$level1" ]
                        then
                                mkdir "/var/www/music/xml/albums/$level1"
                        fi

################################################## HERE
                        echo "<album albumTitle=\"$level2\" XMLLink=\"xml/albums/$level2.xml\"></album>" >>"$albumFilename"
                        trackFilename="/var/www/music/xml/albums/$level2.xml"
                else
                        trackFilename="/var/www/music/xml/albums/$level1.xml"
                fi
                touch "$trackFilename"
                echo "<album>" >"$trackFilename"
                #parse each mp3 file for info and insert to xml file

                if [ -d "$level2" ]
                then
                        for title in "$level2"/*.mp3
                        do
                                mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$trackFilename"
                                mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$allTracks"
                        done
                else
                        for title in "$level1"/*.mp3
                        do
                                mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$trackFilename"
                                mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$allTracks"
                        done
                fi
                if [ -f "$level2" ]
                then
                        echo "<album albumTitle=\"$level2\" XMLLink=\"xml/albums/$level1.xml\">" >>"$albumFilename"
                fi

                echo "</album>" >>"$trackFilename"
        done
        echo "</artist>" >>"$albumFilename"
done

echo "</allTracks>" >>"$alltracks"
echo "</artists>" >>"$artistFilename"
I put a comment where the problem is.

$title2 outputs to '$title1/*' where * is anything in folder '$title1'

i need to strip out everything before the '/' in $title2. i tried using sed with the 'D' opperand but couldn't get it to work. any help is much appreicated.

thanks in advance,

Phil V
 
Old 03-16-2006, 04:52 AM   #2
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
I don't even see title1 or title2 in that script? Are you perhaps thinking about level1 and level2?

Quote:
i need to strip out everything before the '/' in $title2.
To strip the path part of a filename use basename command, e.g.
$ title2=/path/to/mymusic/title2.mp3;basename $title2
title2.mp3
 
Old 03-16-2006, 05:54 PM   #3
crewblunts
Member
 
Registered: Jan 2004
Location: Connecticut, USA
Distribution: Slackware & Ubuntu
Posts: 53

Original Poster
Rep: Reputation: 15
thank you very much sir.
I am going to try it straight away!
 
  


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
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
looking for string on particular line - bash script tara Linux - General 9 12-14-2005 05:43 PM
Simple bash script help, grabbing part of a string colabus Linux - Newbie 3 04-25-2005 09:42 AM
Getting the first part of a filename in a BASH script trevelluk Programming 3 02-15-2005 01:06 AM
Bash Script String Splitting MurrayL Linux - Newbie 1 09-21-2004 03:20 AM


All times are GMT -5. The time now is 07:03 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