Find the answer to your Linux question:
Results 1 to 2 of 2
I am trying to add some html code to a line that is generated by a bash script. Here is the line: Summary of events for server1 for Thu Jun ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    15

    SED: Add html code to whole line.

    I am trying to add some html code to a line that is generated by a bash script.

    Here is the line:

    Summary of events for server1 for Thu Jun 30 2011

    I want it to look like this with a red color:

    Summary of events for server1 for Thu Jun 30 2011


    I need to append the html tags:

    <span style="color=red"> to the beginning AND
    </span> to the end.

    I've got it somewhat, but when I run the script I get only the word Summary, for example in red. I can't figure out how to grab the whole line and change it. I can not just retype the line word for word because each day it will change i.e. the date for example. The words "Summary of events for" will be consistent, but the date and server name will change.

    Do I need to do this in two steps?

    Thanks to all you sed masters.

  2. #2
    Linux User
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    262
    say the script "getdata" is producting:
    Code:
    just another line of data
    Summary of events for server1 for Thu Jun 29 2011
    Summary of events for server1 for Thu Jun 30 2011
    Summary of events for server2for Thu Jun 29 2011
    Summary of events for server2 for Thu Jun 30 2011
    just another line of data
    junk Summary of events for server2for Thu Jun 29 2011
    then the command:
    Code:
    getdata | sed 's:\(^Summary of events for .*\):<span style="color=red">\1</span>:'
    Which would produce:
    Code:
    just another line of data
    <span style="color=red">Summary of events for server1 for Thu Jun 29 2011</span>
    <span style="color=red">Summary of events for server1 for Thu Jun 30 2011</span>
    <span style="color=red">Summary of events for server2for Thu Jun 29 2011</span>
    <span style="color=red">Summary of events for server2 for Thu Jun 30 2011</span>
    just another line of data
    junk Summary of events for server2for Thu Jun 29 2011

Posting Permissions

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