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!

Sed problem

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
One of the variables, I have:

DATE="04/15/2003"

Then I do a sed:
cat ${filename} | sed -e s/"Start Date:"/"${DATE}"/ > ${RUNDIR}/status.new

Because DATE contains '/', it screwed up the file. 'status.new' becomes 0 length file. How do I fix the problem or how do I change the variable $DATE to "04\/15\/2003"?
 
sed -e "s=Start Date:=${DATE}=" ${filename}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi,
As vgersh99 points out. Use a different delimiter like the '=' sign.

----
 
You could change the variable to

DATE=&quot;04\/15\/2003&quot;

or

DATE=&quot;`date '+%m\/%d\/%Y'`&quot;

or even

cat ${filename} | sed -e &quot;s/Start Date:/`date '+%m\/%d\/%Y'`/&quot; > ${RUNDIR}/status.new

Of course if you use the variable in other places in your script then you have to worry about the back slashes, so Vlad's solution is the best and certainly the most readable.


Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top