i am agree with Franklin52.You can use any character that is not used in the entire expression for any other purpose as a separator instead of slash /.But there is another way here-
shell can be made to ignore special meaning of embedded slashes and treat them as literals by using backslash.So,use \ for each separating slash in date field like dd\/mm\/yyyy.
you can use the different delimiters/separator in the almost all of the seds.(all available for GNU sed but forget the special means of thats for shells.)
but we prefer / delimiter for more readable..
but if your string contains same chars with sed's delimeter then we can try change it.
some ones ,:|;#@!%
if u can use "/" then you have to escape the slahs
# sed "s/insert/$(echo ${STR1//\//\\\/})/g" file
and usage single/double quotes may like this in te sed expr.
--> double quotes usefull when expand variable (especially variable contains special meaning variables [white spaces,slashes,the other variables with back slahes..)
sed "s|insert|$STR1|g" file
--> single quotes usefull when our variable does not contain these chars but we have to use double quotes at the front of the STR1 because of escape for these special variables..
sed 's;insert;'"$STR1"';g' file
--> if the STR1="04/18/2012" may we can use only single quotes, because of STR1 is a string without space
---------- Post updated at 07:56 PM ---------- Previous update was at 07:42 PM ----------
I tested sed "s/insert/$(echo ${STR1//\//\\\/})/g" file
as well, working fine to me. Giving the same result as sed "s#insert#$STR1#g" file
Thanks to ygemici & all.
Thanks|Suresh
---------- Post updated at 09:06 PM ---------- Previous update was at 07:56 PM ----------
Hi,
Thanks for your previous posts. I have another requirement with little different output. The sed "s#IncludeDateTime =#IncludeDateTime =$STR1#g" file1.
This is appending the new value to the existing value. what I want is the existing value removed and assign new value. eg. $$IncludeDateTime =04/18/2012 11:38:55 01/01/2011 10:55:37. So what I want from the above command is $$IncludeDateTime =04/18/2012 11:38:55 and should not append the exising value 01/01/2011 10:55:37.
Or exising entire line should be removed and new line to be added with the new results.
Can any one please help in this regard.
Heartful Thanks to all in advance. Thanks | Suresh