[Solved] sed - how replace date in script

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 :

sed -e "s|PREV_DTE=|PREV_DTE=${PRE_DT_TO}|" < input_file > output_file

But the output i am getting is

PREV_DTE=09/15/201309/30/2013

Please help on how to achieve this !

Regards,

Hello,

It's a kind request please use code tags while posting queries.
Here is the following which may help you.

echo "09/15/2013" | awk -v new_date="09/30/2013" '(sub($0,new_date))'
09/30/2013

Thanks,
R. Singh

Try:

$ date -d"09/15/2013 + 15 day" +%m/%d/%Y
09/30/2013
$ echo "09/15/2013" | awk '$1=Newdate' Newdate="09/30/2013"
09/30/2013

Try:

sed -e "s|PREV_DTE=../../....|PREV_DTE=${PRE_DT_TO}|" < input_file > output_file
1 Like

Thanks Don Cragun ! It worked...