0

I am trying to replace a variable value in my file using bash.

Input string ----- preprocess_date=06/24/2020_17:00

Expected string ----- preprocess_date=06/24/2020_17:10

I have the value 06/24/2020_17:10 in prep_tmp variable. I have tried the below command:

sed -i s/preprocess_date=.*/preprocess_date=${prep_tmp}/

I'm getting the error sed: -e expression #1, char 43: unknown option to `s'

Can anyone help me on this?

Thanks in advance.

user3497321
  • 443
  • 2
  • 6
  • 15
  • 1
    use "-s around your sed expression and a diff separator: ```sed -i "s#preprocess_date=.*#preprocess_date=${prep_tmp}#"``` – vgersh99 Aug 05 '20 at 13:34
  • Please note when you search here for `[sed] unknown option to` there are already 270 Q/As. – shellter Aug 05 '20 at 13:41

1 Answers1

2

Your command with the 3 seperating /:

sed -i s/preprocess_date=.*/preprocess_date=${prep_tmp}/
        ^                  ^                           ^

expands to:

sed -i s/preprocess_date=.*/preprocess_date=06/24/2020_17:10/
        ^                  ^                  ^

with 24/2020_17:10/ overflowing after the s command

To solve this problem you can replace all the sperarating / with some other character. I like using the | (but also needs " to ensure that they are not parsed as pipes by a shell)

sed -i "s|preprocess_date=.*|preprocess_date=${prep_tmp}|"
MaanooAk
  • 2,418
  • 17
  • 28