I answered as followshakerdefo wrote: I need your help
Sent: 2015-08-05 22:02
by hakerdefo
Hi there kiyop,
I need your help regarding a bash script. I'm working on a script and in that script I need to parse 'StreamTitle' from shoutcast-icecast radio streams. I'm using mpg123 to play the streams. Now with the help of grep and sed I've been able to extract the 'StreamTitle' but here comes my problem. As the track changes in the radio stream the last played track remains on the screen and currently playing track appears below it. Like this,In the above example 'The Rolling Stones - Jumpin Jack Flash' was the track last played and 'Bruce Springsteen - Cover Me' is the currently playing track. As we continue to play the radio stream the list will keep growing. Now I want only the currently playing track displayed in terminal. I don't want the previously played tracks to appear. Is it possible via pure bash solution? Any ideas?Code: Select all
The Rolling Stones - Jumpin Jack Flash Bruce Springsteen - Cover Me
Here is the bash one liner I'm currently using,Thanks in advance!Code: Select all
mpg123 http://streaming.radionomy.com/-1ClassicRock 2>&1 /dev/null | grep "StreamTitle" | sed -e 's/;.*//' -e 's/.*=//' -e "s/'//g"
Cheers!!!
Then, hakerdefo replied as follows:kiyop wrote:Re: I need your help
Sent: 2015-08-07 18:44
by kiyop
If you want to display only the last line of standard output (stdout), addsuch asCode: Select all
|tail -n1
ReferCode: Select all
mpg123 http://streaming.radionomy.com/-1ClassicRock 2>&1 /dev/null | grep "StreamTitle" | sed -e 's/;.*//' -e 's/.*=//' -e "s/'//g"|tail -n1
If you want to display only the 2nd line of the standard output, use sedCode: Select all
man tail
ReferCode: Select all
|sed -n 2p
Code: Select all
man sed
Thus, I replied as follows:hakerdefo wrote:Re: I need your help
Sent: 2015-08-08 00:41
From: hakerdefo
To: kiyop
Thanks for the idea but I already tried it! It didn't work. Adding 'tail -n1' prevents anything from appearing on stdout. Only when you stops mpg123, title of the song that was playing appears on the screen.
Did you try it? I tried it across three different distros and different terminal emulators and the result remains the same.
Could you please help hakerdefo?kiyop wrote:Re: I need your help
Sent: 2015-08-08 13:26
by kiyop
I have never used mpg123 nor http://streaming.radionomy.com/-1ClassicRock.
So I do not know how the output of the followingcomes.Code: Select all
mpg123 http://streaming.radionomy.com/-1ClassicRock 2>&1 /dev/null
It outputs the info of a song whenever it starts playing a new song, doesn't it?
I cannot understand what you want to do.
Where do you execute the command? On a terminal window on GUI? Or on a tty?
Do you want to delete the info of the former song which has been displayed on a terminal, when a new song is started to be played?
If so, you can use "clear" command to delete all the info on the terminal.
But another person may know better way.
Why not posting this question of yours on one of debian user forums directly, instead of asking to me?