Find the answer to your Linux question:
Results 1 to 7 of 7
Hi I'm trying to use sed to change the title of my xterm, from the output of mplayer. I have put together the following expression: Code: echo "ICY Info: StreamTitle='Artist ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    9

    question about sed

    Hi

    I'm trying to use sed to change the title of my xterm, from the output of mplayer. I have put together the following expression:

    Code:
    echo "ICY Info: StreamTitle='Artist - Song Title';StreamUrl='';" | sed "s/StreamTitle='\([^']*\)/\0\e]0;\1\a/" ;sleep 10
    (The echo and sleep stuff is just for testing)

    For some reason this doesn't work -- The output is :
    Code:
    ICY Info: StreamTitle='Artist - Song Titlee]0;Artist - Song Title';StreamUrl='';
    which makes me think that \e isn't interpreted as an escape-character by sed.

    Any ideas?

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Not sure what you're trying, to extract the artist and the songtitle from the line you can try this:

    Code:
    awk -F "'" '{print $2}'
    Regards

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    9
    I'm trying to pass everything through untouched, but when I have a match for the song-title, I want additionally print \033[0;SONG_TITLE\007 (Where SONG_TITLE is the song title match). In xterm, this escape-sequence will change the title of the console-window.
    I still want the normal output, so everything should pass through untouched -- I just want the escape-sequence in there as an addition to the output.

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi. troelskn.

    For the sed short-coming on \e et al, you may want to consider using perl:
    Code:
          ESCAPE SEQUENCES
    
           These work as in normal strings.
    
              \a       Alarm (beep)
              \e       Escape
              \f       Formfeed
              \n       Newline
    
    -- excerpt from man perlreref
    cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Just Joined!
    Join Date
    Oct 2007
    Posts
    9
    Thanks, but I wanted to use sed -- mostly as a learning exercise. Now, if this is in fact a limitation of sed -- that it's simply impossible to do -- then I'll use Perl for the task, but I just have a hard time accepting that sed can't do what I want it to.

  6. #6
    Just Joined!
    Join Date
    Oct 2007
    Posts
    9
    I figured it out! Instead of using \e, I tried with \x1B, which generates an escape character. I thought I already tried that, but I had used \x33, which is wrong (33 is the same character in octal).

    Thanks for your help none the less

  7. #7
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Good, glad you got it.

    Whilst you were doing that, I was looking at info sed, and found:
    Code:
    `\dXXX'
         Produces or matches a character whose decimal ASCII value is XXX.
    
    `\oXXX'
         Produces or matches a character whose octal ASCII value is XXX.
    
    `\xXX'
         Produces or matches a character whose hexadecimal ASCII value is
         XX.
    
    -- excerpt from info sed
    I dislike looking at info, but man sed and even O'Reilly sed & awk didn't discuss the character sequences (at least not that I could find) ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...