How do I substitue a variable in sed ?

From: Dr. David Kirkby (see_my_signature_for_my_real_address_at_hotmail.com)
Date: 08/12/04


Date: 12 Aug 2004 11:43:06 -0700

I have a short script in which the varable date_and_time is set to
today's date/time. I'd then like to find all lines in a list of html
file that have the words 'Last modified: ...' on the line, and
substitute it with 'Last modified: xxx' where xxx is the date and
time.

The problem is, if I set a variable date_and_time to 12 Aug 20:40, I
end up with the sed script either substituting

a) $date_and_time
b) date_and_time
but never
c) 12 Aug 20:40.

Bascically I need to refer to $date_and_time in the sed substritution,
but I can I ??

Here is my script.

sparrow /var/apache/htdocs/Southminster-branch-line # modified
#!/bin/sh
# The aim of this script is to substitute any line beggining:
# Last modified:
# in an html file with:
# Last modfied date_and_time
# where date_and_time is the time the file was last modified.
for file in `ls *.html`
do
  # This gets the date/time, and puts it into the variable
date_and_time
  date_and_time=`ls -l $file | awk '{print $7,$6,$8}'`

  # Now how do I get sed to put this in ????

  sed 's/^Last modified:.*/Last modified:$foo/g' $file
done
~



Relevant Pages

  • Cant make this page work
    ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
    (comp.lang.javascript)
  • Re: Use with Action "Send Reply" Dont Go
    ... Set Up an HTML Signature ... Go to Tools/Signatures in Entourage, ... "Auto-Reply HTML" or something similar. ... script in the Entourage Script Menu Items folder. ...
    (microsoft.public.mac.office.entourage)
  • Validating to a higher 4.01 standard (long)
    ... The next step is to copy these HTML documents to a new directory (so you do ... onmousedown %Script; #IMPLIED ... datafld CDATA #IMPLIED ... href %URI; #IMPLIED ...
    (alt.html)
  • Posting & Help REQ - Active Directory Reporting Script - pls help add to it
    ... I started writing a script to make a basic HTML report of my active ... ' This code prints out a list of global catalogs for the forest ... Function DisplayDomains (strDomain, strSpaces, dicDomainHierachy) ...
    (microsoft.public.scripting.vbscript)
  • Re: How do I substitue a variable in sed ?
    ... > today's date/time. ... I'd then like to find all lines in a list of html ... > Here is my script. ... > # The aim of this script is to substitute any line beggining: ...
    (comp.unix.shell)