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?

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.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.