the correct format of using the substitution command in sed is:
and inside '....' for variable evaluation use "$variable".
I hope the error should not come now.
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
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..)
--> 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..
--> if the STR1="04/18/2012" may we can use only single quotes, because of STR1 is a string without space
The following script worked well for me.
resulting as
Thanks
Suresh
---------- 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
Last edited by Scrutinizer; 04-19-2012 at 11:15 AM..
Reason: code tags
Hello All,
we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below:
abc.txt
------------------
line1
line2
line3
$$EDWS_DATE_INSERT=08-27-2019
line4
$$EDWS_PREV_DATE_INSERT=08-26-2019
I am trying to... (1 Reply)
I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and
I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server
$ cat temp.txt
RTG*888*TD8*20180201~... (1 Reply)
Hi All,
I have a requirement to find and replace old date with new date value. Below is the scenario:
# In the input file, date is MM/DD/YYYY format
PREV_DTE=09/15/2013
I want to replace with 09/30/2013. It should look like
PREV_DTE=09/30/2013
I am using below sed command :... (4 Replies)
Hello experts.
I haven't been able to find a solution for this using the sed command.
I only want to replace the forward slash with string "FW_SLASH" only if there's a number right after the slash while preserving the original number.
I have a file containing 2 entries:
Original File:... (5 Replies)
Hi,
I wold like to replace this 2012 Mar 02 to this 20120302.
i have already this code:
ls -lrt | awk '{ print $8$6$7 }'| sed -e s/*:*/'2013'/g
-e s/'Jan'/01/g -e s/'Feb'/02/g -e s/'Mar'/03/g -e s/'Apr'/04/g -e s/'May'/05/g
-e s/'Jun'/06/g -e s/'Jul'/07/g -e s/'Aug'/08/g -e... (7 Replies)
Hi all,
Hereby wish to have your advise for below:
Main concept is
I intend to get current directory of my script file.
This script file will be copied to /etc/init.d.
A string in this copy will be replaced with current directory value.
Below is original script file:
... (6 Replies)
Hello,
I have this command and it works fine.
My question is that how can we replace the N by a variable, to print for instance a big number of lines. It means if I want 100 lines after an expression, to not put "N" 100 times in the sed.
Code:
$ sed -n '/aaa/{n;N;N;s///g;s/;/; /g;p;}'... (2 Replies)
Ok, so, let's say I have the variable $GMAILID....How can I use it with sed command so to replace a string in a file? e.g.:
sed -i 's/$GMAILID/test@gmail.com/' /home/$USER/Desktop/sendmail (4 Replies)
Hi,
I am trying tio invoke unix variable in a sed command like below, but it seems to be failing..
a=1
sed -n '$a,$p' file.txt ### Failing
but
a=1
sed -n '1,$p' files.txt ### Works fine
Please help me to fix this... Thanks in advance (2 Replies)
Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line.
... (1 Reply)