1

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below:

abc.txt
------------------
Code:
line1
line2
line3
$$EDWS_DATE_INSERT=08-27-2019
line4
$$EDWS_PREV_DATE_INSERT=08-26-2019

I am trying to write a small command that can update these dates daily with current date but its not replacing the date value.
Code:

sed -i 's/$$EDWS_DATE_INSERT =.*/$$EDWS_DATE_INSERT="$(date `+%y%m%d`)"/' abc.txt

Current result:

$$EDWS_DATE_INSERT="$(date `+%y%m%d`)"

Can anyone help with this?

41754
  • 95
pradeep
  • 11
  • 1
  • 3

2 Answers2

3

Your command has an extra space

sed -i 's/$$EDWS_DATE_INSERT<extra_space>=.*/$$EDWS_DATE_INSERT="$(date `+%y%m%d`)"/' abc.txt

I think what you are looking for is:

sed -i "s/\$\$EDWS_DATE_INSERT=.*/\$\$EDWS_DATE_INSERT=$(date '+%y%m%d')/" abc.txt

Better yet:

sed -E -i "s/(\\\$\\\$EDWS_DATE_INSERT=).*/\1$(date '+%y%m%d')/" abc.txt

Output:

line1
line2
line3
$$EDWS_DATE_INSERT=190827
line4
$$EDWS_PREV_DATE_INSERT=08-26-2019

Replace sed's single quotes for double quotes. Replacing back ticks for single quotes.

EDIT: my previous command was wrong. Updated with fixed command.

0

I use a little script for similar purpose

#!/bin/bash
DATE_NOW=$(date +"%Y/%m/%d %T")
echo "its: $DATE_NOW"
sed -i 's|DEV-BuildTime.*|DEV-BuildTime '"$DATE_NOW"'|' path/to/file

note:

  • don't get the (UTC +N) in the date fearing regexp interpretation
  • use the | for 's' separator (not : nor / that are present in date format)
jo_
  • 172
  • 1
    The required format is %y%m%d, not %Y/%m/%d. What's the relevance of DEV-BuildTime when the question uses $$EDWS_PREV_DATE_INSERT? – Chris Davies Apr 27 '22 at 09:50
  • @roaima my aim isn't to solve a 2 years old bug but to give help to people willing to solve similar problem – jo_ Apr 28 '22 at 07:18