LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-18-2010, 10:33 AM   #76
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556

Not at all -- I've just been at this a little longer than you -- you're welcome though

Of course, for future reference, you should know what the command actually *does*, so you can be "amazing" too

There are lots of AWK tutorials online, and they are not short and simple-- awk is a big item-- but the tutorials give loads of examples.

The -F option tells AWK what to use as a separator; in this case, the slash. So, it separates the input lines at the slashes.
Each item resulting from that separation, is called a FIELD. The fields can be referenced within AWK, by using $1, $2, $3 etc.. In this case, where the filename you want is actually the LAST FIELD, we use $NF, because $NF signifies "NUMBER of FIELDS". So, if the filepath gets separated into X number of pieces, the final piece = $NF.

Sasha

PS - Someone will likely point out that this is a "Useless use of CAT", which means that you can get AWK to read the file itself, rather than catting the file through AWK (to make things a bit more efficient). Something like this:

Code:
awk -F '/' '{print $NF}' $PLAYLIST/$M3UTOPLAY
should result in the same thing.


PPS - sorry for the delay with this last post; it seems my ISP's DNS system is acting up (AGAIN )
 
Old 02-18-2010, 10:38 AM   #77
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
@ schniedz -- good idea re: basename -- that's even simpler.

@ md2dmhot -- By "command-line", does that mean that this is all happening without X? In this case, yes of course, Zenity will not work and a dialog-like thing, as schniedz suggests, would be the way to go.
 
Old 02-18-2010, 10:51 AM   #78
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GrapefruiTgirl View Post
@ schniedz -- good idea re: basename -- that's even simpler.

@ md2dmhot -- By "command-line", does that mean that this is all happening without X? In this case, yes of course, Zenity will not work and a dialog-like thing, as schniedz suggests, would be the way to go.
Lol you trying to confuse a newb..

GrapefruitGirl i think ill try your suggestion first.
 
Old 02-18-2010, 10:51 AM   #79
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by m2dmhot View Post
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
heres an oppertunity to learn the tee command:
Code:
cd "$AUDIOPATH"
    ls -v *.mp3 > "$AUDIOPATH"/tempmp3.lst # Create Temp file with Directory listing in sequence
    cat -n "$AUDIOPATH"/tempmp3.lst | tee outputmp3.lst
man tee for more info.

Last edited by schneidz; 02-18-2010 at 11:01 AM.
 
Old 02-18-2010, 10:59 AM   #80
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Geees lol you guys got me on overload hehe.. Gonna try the tee out and report back
 
Old 02-18-2010, 11:17 AM   #81
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
heres an oppertunity to learn the tee command:
Code:
cd "$AUDIOPATH"
    ls -v *.mp3 > "$AUDIOPATH"/tempmp3.lst # Create Temp file with Directory listing in sequence
    cat -n "$AUDIOPATH"/tempmp3.lst | tee outputmp3.lst
man tee for more info.
ok ran that it works but im sure im not inserting it at the proper point and dont want to put it in between a loop
as of now it shows the full path but it is inputing the # that is typed in instead of the actual mp3 that needs to be there??

Ei
/home/Fedora11/MP3/4
instead of
/home/Fedora11/MP3/blablabla.mp3

Code:
create_playlist() { 

   cd $PLAYLIST
   echo -e "Enter Name Of Playlist --> \c"
   read PNAME
   touch $PNAME.m3u

   echo -e
   find $AUDIOPATH/*.mp3 -exec basename {} \;
   echo -e

   echo -e "How Many Songs Would You Like To Add 1,2,3..etc(#)? --> \c"
   
   read NUM_OF_SONGS

    cd "$AUDIOPATH"
    ls -v *.mp3 > "$AUDIOPATH"/tempmp3.lst # Create Temp file with Directory listing in sequence
    cat -n "$AUDIOPATH"/tempmp3.lst | tee outputmp3.lst 
 
   for ((i=1; i<=$NUM_OF_SONGS; i++)) ; do
     echo "Please Type In Mp3 To Add To Playlist ==> "
     read MP3_FILE

     echo $AUDIOPATH/$MP3_FILE >> $PLAYLIST/$PNAME.m3u 
   done

}

Last edited by m2dmhot; 02-18-2010 at 11:21 AM.
 
Old 02-18-2010, 11:27 AM   #82
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ not quite sure what you mean. could you please post the output of what it is doing and what you expect it to do ?
 
Old 02-18-2010, 12:59 PM   #83
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
^ not quite sure what you mean. could you please post the output of what it is doing and what you expect it to do ?
Below is my inputs

Mp3 Playlist Program:
================================
A)Create Mp3 Playlist
B)Display Mp3 Playlists
C)View Playlist
D)Play Mp3 Playlist
E)Shuffle Playlist
F)Add Mp3 To Playlist
G)Remove Mp3 From Playlist
H)Clear Mp3 Playlist
I)Generate Mp3 Database
J)Play Mp3
K)Copy Mp3
L)Delete Mp3
Q)Quit
Enter your selection ==> a
Enter Name Of Playlist --> linuxquestions

01-inna_-_hot_(play_and_win_radio_version).mp3
01-pitbull_feat._nicole_scherzinger-hotel_room_service_(126_bpm)_(remixed_by_dj_absinth)-umt.mp3
02-kesha--tik_tok_(tom_nevilles_crunk_and_med_vocal_mix)-wus.mp3
03-medina-you_and_i_(spencer_and_hill_remix).mp3
Deepest Blue - Give It Away (Radio Edit).mp3
DJ Antoine - Underneath (Radio Mix).mp3
Energy Club House - Justin Dohman 1.mp3
Public Domain - Operation Blade 2009 (Radio Edit).mp3
Rockefeller - Do It 2 Nite (Radio Edit).mp3
The Kic Pimpz - No Stopping Us (Radio Edit).mp3

How Many Songs Would You Like To Add 1,2,3..etc(#)? --> 2
1 01-inna_-_hot_(play_and_win_radio_version).mp3
2 01-pitbull_feat._nicole_scherzinger-hotel_room_service_(126_bpm)_(remixed_by_dj_absinth)-umt.mp3
3 02-kesha--tik_tok_(tom_nevilles_crunk_and_med_vocal_mix)-wus.mp3
4 03-medina-you_and_i_(spencer_and_hill_remix).mp3
5 DJ Antoine - Underneath (Radio Mix).mp3
6 Deepest Blue - Give It Away (Radio Edit).mp3
7 Energy Club House - Justin Dohman 1.mp3
8 Public Domain - Operation Blade 2009 (Radio Edit).mp3
9 Rockefeller - Do It 2 Nite (Radio Edit).mp3
10 The Kic Pimpz - No Stopping Us (Radio Edit).mp3
Please Type In Mp3 To Add To Playlist ==> 1
Please Type In Mp3 To Add To Playlist ==> 2

I would like the above in orange to correspond with the mp3 that it is actually listing and put that in the m3u file.
As of now it just list the path. Not the song.
Contents of the m3u below ->
/home/woot/MP3/1
/home/woot/MP3/2

Last edited by m2dmhot; 02-18-2010 at 01:02 PM.
 
Old 02-18-2010, 01:55 PM   #84
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
the easiest way to debug is to put in echo's after you store a variable:
e.g.:
Code:
   for ((i=1; i<=$NUM_OF_SONGS; i++)) ; do
     echo "Please Type In Mp3 To Add To Playlist ==> "
     read MP3_FILE
echo debug: MP3_FILE = $MP3_FILE
     echo $AUDIOPATH/$MP3_FILE >> $PLAYLIST/$PNAME.m3u 
   done
you have to somehow enumerate the index of the file to the actual file name.
i suggest sed.
maybe [untested]
Code:
sed -n "$MP3_FILE"p outputmp3.lst | awk '{print $2}'
will work (fyi, it will choke on filenames with spaces).

Last edited by schneidz; 02-18-2010 at 02:42 PM.
 
Old 02-18-2010, 07:19 PM   #85
m2dmhot
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 15
kind of stuck here again i got the create playlist with # variables done listing the proper mp3 file in the playlist ..
Now im trying to list the contents of the playlist in corespondence to a number variable punched in by user

Code:
view_playlist() { 
 
    cd "$PLAYLIST"
    ls -v *.m3u > "$PLAYLIST"/tempm3u.lst # Create Temp file with listing of m3u's in sequence
    cat -n "$PLAYLIST"/tempm3u.lst | tee outputm3u.lst 
   echo -e  ==================================================================================================================================================================================================
   echo -e "Please Type In The Playlist # You Wish To View --> \c"
   read VIEWPLAYLIST
    
    # Test if user entered number only
      if [[ ! $VIEWPLAYLIST =~ ^[0-9]+$ ]]; then
         echo "ERROR: NUMBERS ONLY JERKY!!!"
         fi 

}
So im thinking i have to cat the read VIEWPLAYLIST ??? but link it to the outputm3u.lst stumped there

Last edited by m2dmhot; 02-18-2010 at 07:49 PM.
 
Old 02-18-2010, 11:54 PM   #86
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Have you considered using bash's "select" built-in for the menus? More info by help select.
 
Old 02-19-2010, 09:41 AM   #87
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
@m2dmhot: i'm having a hard time deciphering what you mean, could you please post the output of what the program is doing versus what you want it to do ?

bonus:
this would be slightly cleaner: [untested]
Code:
cd "$PLAYLIST"
ls -v *.m3u | grep -n . | tee "$PLAYLIST"/outputm3u.lst # Create Temp file with listing of m3u's in sequence
i think the answer would be similar to my post #84.
you will have to play around with sed and awk to print the line that you want.

Last edited by schneidz; 02-19-2010 at 09:48 AM.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:23 AM.

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
Open Source Consulting | Domain Registration