8

I execute a sed command in my script:

sed -i "${1}s/${2}=.*/${2}=${REPLY}/" $3

this is the echo:

sed -i 13s/log4j.appender.ROOT2.File=.*/log4j.appender.ROOT2.File=/app/TET/log.log/ /applis/DIAPASON/diapason1/conf/log4j.properties

My error:

sed: -e expression n°1, character 61: unknown option fors`'

terdon
  • 242,166
Mercer
  • 836
  • 5
  • 11
  • 22

2 Answers2

15

You have multiple / characters inside the $REPLY variable, which is confusing sed.

You can choose an alternate delimiter for the s/// command in most versions of sed, so if this were me, I'd try something like:

sed -i "${1}s|${2}=.*|${2}=${REPLY}|" $3

This replaces the / for sed with |, so that the / in ${REPLY} are (hopefully) not interpreted by sed.

Kusalananda
  • 333,661
John
  • 17,011
  • 1
    "...in most versions of sed" — actually, any version of Sed that is POSIX compliant can use any character other than a newline or a backslash as a delimiter for the s command. – Wildcard Oct 11 '17 at 23:39
2

Use any character as a s command delimiter, Please find following example

sed -Ei "s|$k|$j|g" filename.txt