Computing.Net > Forums > Unix > pattern matching/replacing with sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

pattern matching/replacing with sed

Reply to Message Icon

Name: MVal
Date: January 11, 2005 at 13:41:09 Pacific
OS: HPUX
CPU/Ram: HP
Comment:

Hi,

I am trying to do the following simple operation with sed, but it wouldnt work because sed doesn't allow me to use variables in the replace string. Anyway to do it ?

testvar="TestFilename.#.txt"
testdate=`date +%m%d%Y`

resultvar=`echo $testvar | sed -e s/#/$testdate`

Here $testdate in the expression fails.

Basically I want to replace the "#" with today's date.

Your help is appreciated ...

regards
-MVal



Sponsored Link
Ads by Google

Response Number 1
Name: vgersh99
Date: January 11, 2005 at 13:53:38 Pacific
Reply:

resultvar=`echo $testvar | sed -e "s/#/$testdate/"`


0

Response Number 2
Name: nails
Date: January 11, 2005 at 13:55:17 Pacific
Reply:

You forgot the terminate /:

resultvar=`echo $testvar | sed -e s/#/$testdate/`


0

Response Number 3
Name: MVal
Date: January 11, 2005 at 14:02:28 Pacific
Reply:

Thanks vgersh99, putting the replace statement in double quote solves the problem..

Thank nails, yes I forgot the ending '/' also...



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: pattern matching/replacing with sed

Find and replace with sed or awk www.computing.net/answers/unix/find-and-replace-with-sed-or-awk/8099.html

String Replacement w/ Sed www.computing.net/answers/unix/string-replacement-w-sed/5429.html

File Pattern Matching www.computing.net/answers/unix/file-pattern-matching/6170.html