LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2010, 11:13 PM   #61
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15

Quote:
Originally Posted by evo2 View Post
You seem to be missing the last line in penguiniators post #53



Evo2.
Na somethings not right now its not working anymore

Code:
copy_mp3() { 
   
    cd "$AUDIOPATH"
    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

    echo -e "Please Select Your Song To Copy --> \c"
    read "DONKEY"

while read line; do
                              
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp "$DONKEY" "$PLAYLIST"
       fi
     
       < "$AUDIOPATH"/tempdir.lst

       rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing  
       done
}
 
Old 02-17-2010, 11:14 PM   #62
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Code:
copy_mp3() { 
   
    cd "$AUDIOPATH"
    ls -v *.mp3 >> "$AUDIOPATH"/tempdir.lst # Create Temp file with Directory listing

    cd "$AUDIOPATH"
    ls -v *.mp3
    echo -e 

    echo -e "Please Select Your Song To Copy --> \c"
    read "DONKEY"

while read line; do
                              
        if [ "$line" = "$DONKEY" ]; then
            echo "File Already Exist, Copy Aborted!"
        else
            cp "$DONKEY" "$PLAYLIST"
       fi
     
done < "$AUDIOPATH"/tempdir.lst

       rm "$AUDIOPATH"/tempdir.lst # Delete the temporary file containing the directory listing  

}
 
Old 02-17-2010, 11:14 PM   #63
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by penguiniator View Post
Just out of curiosity... what text editor are you using to write your script?
Gedit
 
Old 02-17-2010, 11:21 PM   #64
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
OK that worked great.. Now one more touch i would like to add to my script is it at all possible to assign the results when it list the mp3 or m3u as a # or letter variable so i can select it instead of typing in the full name (more chance of user error) ????

Example

(1)total_bla_bla.mp3
(2)me_at_home.mp3
(3)brige_yes_bla_blalal_oooooo_alala.mp3
...etc

But also have ability to select like 1,2,3,13 ENTER
 
Old 02-17-2010, 11:34 PM   #65
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Anything is possible.. Where I would start:

When you do the `ls` command to create the temporary file, I would pipe that `ls` through a `cat -n` in order to produce a line number at the start of each line. Do the same thing with the second `ls` command which presents the list to the user.
Now, when the user inputs an item for selection (for copying) you will need to perform some checking of the input, to see whether or not is it a number, or a title; in other words, $DONKEY will end up being either "a number", or a text string ending with ".mp3" (and if it's neither of these, quit with an error).
If it's a text-string.mp3, then proceed as you currently are doing, though you'll need to account for the line numbers in the temp file. If it's a NUMBER, then you'd need to parse the temporary file to locate the line number matching the number entered, and grab the filename.

This would be rather easy, using maybe `awk` to parse the temporary file to read the filename from the correct line, however it is less easy than it could be, because of the spaces in the filenames. However, this can be worked around by simply finding the correct line of the temp file (by line number) and using `sed` to prune off the first field (which will be the line number, including the space following the line number) and presto -- there's your filename.

Anyhow, this is where I'd start. May sound complex, but not really too too complex; though I realize, this is early in your scripting experience, so one thing at a time.. The first thing I'd do, if I were you and you want to go this route that I've described, is read the man page for cat, and then try adding the pipe and cat command to the `ls` commands you already have. We'll see where to go from there.

Sasha

Last edited by GrapefruiTgirl; 02-17-2010 at 11:35 PM.
 
Old 02-18-2010, 09:06 AM   #66
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,076

Rep: Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861
^ also, consider using a zenity pop-up menu.

my response #10 links to an example.
 
Old 02-18-2010, 09:36 AM   #67
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
^ also, consider using a zenity pop-up menu.

my response #10 links to an example.
this all has to be done in cmd prompt. So the checkbox is outta the question i assume??
 
Old 02-18-2010, 09:41 AM   #68
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Not at all

A bash script is after all, just a sequence of cmd-line commands.
 
Old 02-18-2010, 09:48 AM   #69
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
my newest task with this script is to remove the path in the playlist without actually modifying the file


PLAYLIST=/home/woot

AUDIOPATH=$PLAYLIST/MP3

Code:
view_playlist() { 
    cd "$PLAYLIST"
    ls -v *.m3u
    echo -e
    echo -e "Please Type In The Playlist You Wish To View --> \c"  
    IFS= read M3UTOPLAY
    cat  $PLAYLIST/$M3UTOPLAY
}
when i run this code it shows the full path. Is there anyway to to show the contents of the file without the full path
example
instead of /home/woot/blablabla.mp3
blablabla.mp3

i think its with the sed cmd but unsure how to do it???

Last edited by m2dmhot; 02-18-2010 at 09:49 AM.
 
Old 02-18-2010, 09:54 AM   #70
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
if it's the line cat $PLAYLIST/$M3UTOPLAY which is showing the full path, try this:

Code:
cat $PLAYLIST/$M3UTOPLAY | awk -F '/' '{print $NF}'
** untested, so if it fails, show us the output.

Sasha
 
Old 02-18-2010, 10:00 AM   #71
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Your amazing lol thanks
 
Old 02-18-2010, 10:01 AM   #72
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GrapefruiTgirl View Post
if it's the line cat $PLAYLIST/$M3UTOPLAY which is showing the full path, try this:

Code:
cat $PLAYLIST/$M3UTOPLAY | awk -F '/' '{print $NF}'
** untested, so if it fails, show us the output.

Sasha
Worked like a charm thanks..

Now i will try to tackle the previous post you stated
 
Old 02-18-2010, 10:07 AM   #73
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,076

Rep: Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861
^ also, man basename
 
Old 02-18-2010, 10:15 AM   #74
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,076

Rep: Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861Reputation: 861
Quote:
Originally Posted by m2dmhot View Post
this all has to be done in cmd prompt. So the checkbox is outta the question i assume??
ok, maybe dialog would be appropriate then.

although, the experience gained from re-implimenting a dialog-like program is more valuable, i think.

good job, so far.

Last edited by schneidz; 02-18-2010 at 10:27 AM.
 
Old 02-18-2010, 10:28 AM   #75
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GrapefruiTgirl View Post
Anything is possible.. Where I would start:

When you do the `ls` command to create the temporary file, I would pipe that `ls` through a `cat -n` in order to produce a line number at the start of each line. Do the same thing with the second `ls` command which presents the list to the user.
Now, when the user inputs an item for selection (for copying) you will need to perform some checking of the input, to see whether or not is it a number, or a title; in other words, $DONKEY will end up being either "a number", or a text string ending with ".mp3" (and if it's neither of these, quit with an error).
If it's a text-string.mp3, then proceed as you currently are doing, though you'll need to account for the line numbers in the temp file. If it's a NUMBER, then you'd need to parse the temporary file to locate the line number matching the number entered, and grab the filename.

This would be rather easy, using maybe `awk` to parse the temporary file to read the filename from the correct line, however it is less easy than it could be, because of the spaces in the filenames. However, this can be worked around by simply finding the correct line of the temp file (by line number) and using `sed` to prune off the first field (which will be the line number, including the space following the line number) and presto -- there's your filename.

Anyhow, this is where I'd start. May sound complex, but not really too too complex; though I realize, this is early in your scripting experience, so one thing at a time.. The first thing I'd do, if I were you and you want to go this route that I've described, is read the man page for cat, and then try adding the pipe and cat command to the `ls` commands you already have. We'll see where to go from there.

Sasha
on the right track here

Code:
cd "$AUDIOPATH"
    ls -v *.mp3 > "$AUDIOPATH"/tempmp3.lst # Create Temp file with Directory listing in sequence
    cat -n "$AUDIOPATH"/tempmp3.lst > outputmp3.lst
    cat outputmp3.lst
 
  


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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 10:53 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration