Making a play-list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making a play-list
# 1  
Old 07-31-2012
Making a play-list

approximately the same question as the last time, but unfortunately I didn't get
a working answer.

I made a script with bash and gtkdialog that create a play-list. The output is for example :
Code:
gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 28897 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip
gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 13746 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip
gtk-media-pause | CB60471-07 - Campbell, Craig - Fish.zip | 6225 | /home/floris/Muziek/Karaoke/1341838939/CB60471-07 - Campbell, Craig - Fish.zip
gtk-media-pause | CB60471-08 - Rimes, LeAnn - Give.zip | 3386 | /home/floris/Muziek/Karaoke/1341838939/CB60471-08 - Rimes, LeAnn - Give.zip

I'm trying the move a song up the list..
In other words, how can I swap two lines?

I tried:
Code:
## $LIST is the play-list file
## $LINE is a random line from the play-list
## $UP_LINE is the line before $LINE
sed "s?$LINE?$UP_LINE?g;s?$UP_LINE?$LINE?g" "$LIST">"$LIST".bak

cat $LIST.bak
gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 28897 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip
gtk-media-pause | CB60471-07 - Campbell, Craig - Fish.zip | 6225 | /home/floris/Muziek/Karaoke/1341838939/CB60471-07 - Campbell, Craig - Fish.zip
gtk-media-pause | CB60471-07 - Campbell, Craig - Fish.zip | 6225 | /home/floris/Muziek/Karaoke/1341838939/CB60471-07 - Campbell, Craig - Fish.zip
gtk-media-pause | CB60471-08 - Rimes, LeAnn - Give.zip | 3386 | /home/floris/Muziek/Karaoke/1341838939/CB60471-08 - Rimes, LeAnn - Give.zip

The expected is
Code:
gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 28897 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip
gtk-media-pause | CB60471-07 - Campbell, Craig - Fish.zip | 6225 | /home/floris/Muziek/Karaoke/1341838939/CB60471-07 - Campbell, Craig - Fish.zip
gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 13746 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip
gtk-media-pause | CB60471-08 - Rimes, LeAnn - Give.zip | 3386 | /home/floris/Muziek/Karaoke/1341838939/CB60471-08 - Rimes, LeAnn - Give.zip

I hope that someone give me an example with sed, awk, perl or any other line editor.

note: The play-list is random made. I only know the line I have selected. So a
solution with line numbers doesn't work. Also please notice that the variables can
contain almost any character.
# 2  
Old 07-31-2012
Hi
Something like that ?

Code:
awk '{if (match($0,/Campbell/)) print; else { if (p) print p; p=$0 } } END {if (p) print p}' songs

This User Gave Thanks to Chirel For This Post:
# 3  
Old 08-01-2012
Thanks Chirel that worked.Smilie
Can you explain the awk line, because I want to understand why it works?

Thanks again.
# 4  
Old 08-01-2012
Hi

sure i can
Code:
awk '                         ## Let's call awk
{                             ## For each line of the file
if (match($0,/Campbell/))     ## Test if the word Campbell is in current line
  print;                      ## If so then just print it.
else {                        ## Else If current Line don't have the word Campbell
  if (p)                      ## Is there a previous line ?
    print p;                  ## Then print previous line.
  p=$0                        ## Previous line = current line.
}
}
END {                         ## We reach end of file
  if (p)                      ## Is there a Previous line left to print ?
    print p                   ## Then print it.
}'                            ## End of awk script.
 songs                        ## File name to read with awk.

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Play sound

hi i want to produce digit sounds.for ex: if my input text is four five six then code should able to produce sounds corresponding to digits which are stored in some directory as four.wav,five.wav etc.Please help me (8 Replies)
Discussion started by: sreejithalokkan
8 Replies

2. Shell Programming and Scripting

Problem in making a list with awk

Hi bodies,I am doing a list from a .txt file with awk commands but something is wrong. The .txt file looks like: 32782 28 18 32783 02 18 32784 01 18 32785 29 18 32786 25 23 32787 25 18 32788 00 18 32789 25 26 32790 02 23 32791 29 26 ... (2 Replies)
Discussion started by: Behrouzx77
2 Replies

3. Shell Programming and Scripting

making a list matching certain criteria in bash...

Hello everyone!I am trying to make a mail list(a simple .txt file)in which i put certain records that match specific criteria. Let's say that i have a(sorted by last column file)like this one: 0100567 Bla1 Lala1 100 1234567 Bla2 Lala2 80 8769029 Bla3 Lala3 70 1001007 ... (0 Replies)
Discussion started by: bashuser2
0 Replies

4. Linux

how can i play the gam

can some1 tell me how to start playing? (2 Replies)
Discussion started by: 123456
2 Replies

5. UNIX for Advanced & Expert Users

play

dear friends, i have linux system . can i play songs in linux system. like winamp player in windows. let me know. (2 Replies)
Discussion started by: rajan_ka1
2 Replies

6. UNIX for Dummies Questions & Answers

How Can I Play A Cd On Unix

HI I AM A FRESH NEW USER ...I MEAN I JUST GOT A COMPUTER ALMOST FOR FREE AND IT RUNS UNIX WHICH I DIDN'T EXPECT AND DONT KNOW HOW TO WORK ON IT I THOUGHT IT'LL BE WITH WINDOWS ..YOU KNOW SO HOW DO I PLAY A CD IN IT. REMEMBER I KNOW NOTHING ABOUT UNIX , BUT I THINK I'LL GET OVER IT... (1 Reply)
Discussion started by: IMOTEB
1 Replies

7. UNIX for Advanced & Expert Users

Need something new to play with

I posted this question in the dummies forums, but I would like to get a more expert opinion... I am looking for a new OS to play with. I have a celron 450 running slackware linux, a powermac G4 450 running Mac OS X (Which by the way has 81 days of uptime as of this moment), a PowerBook G3 running... (5 Replies)
Discussion started by: dewhite04
5 Replies

8. UNIX for Dummies Questions & Answers

play cd? how?

hi all, How do I set up my cdrom to play some regular audio cd (not cd-r or cd-rw). I know that my cdrom has been mounted as it does pop up the file manager if I put in, e.g., the office52 cd. Thanks in advance. Andre (3 Replies)
Discussion started by: andrec
3 Replies
Login or Register to Ask a Question