Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Problem

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
Suppose I have this line in a file name "temp.8639"
<!--Lab Accept Date-->Somedate

How do I run a sed command to replace this line with:

<!--Lab Accept Date-->Newdate

This is the command I used, but not worked:
cat temp.8639 | sed -e s/&quot;<!--Lab Accept Date-->\(.*\)&quot;/&quot;<!--Lab Accept Date-->Newdate&quot;/
Thanks!
 
Here's an awk..

#!/bin/sh
NEWDATE=whatever_the_new_date_is
awk -v newdate=$NEWDATE -F> '{printf(&quot;%s%s\n&quot;, $1, newdate}' temp.8693


Here's a sed...

sed 's/\(!<--Lab Accept Date-->\).*/\1Newdate' temp.8693


 
Try this:
cat temp.8639 | sed 's/<!--Lab Accept Date-->\(.*\)/<!--Lab Accept Date-->Newdate/'
-Brent
 
not fish, nor cheese

note the &quot; instead of ' ans the '$'
#!/bin/sh
Newdate=`date` # or what ever you want
sed &quot;s/\(!<--Lab Accept Date-->\).*/\1$Newdate&quot; temp.8693

forget the cat|sed
sed is old enougth for opening inputfiles
sed ... filename


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top