sed command removing # [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
How to ensure that string interpolated into `sed` substitution escapes all metachars
1 answer
I am using below sed command, but if MacAddressPasswordeRegisteryValue
is WElcome12#
then its producing WElcome12
and removing #
. Any way to avoid it?
sed -i "s#^mac.address.sftp.user.password=.*#mac.address.sftp.user.password=$MacAddressPasswordeRegisteryValue#*=#" $APP_CONFIG_FILE
sed
marked as duplicate by don_crissti, roaima, Rui F Ribeiro, Jeff Schaller, Kusalananda Apr 20 at 15:26
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
How to ensure that string interpolated into `sed` substitution escapes all metachars
1 answer
I am using below sed command, but if MacAddressPasswordeRegisteryValue
is WElcome12#
then its producing WElcome12
and removing #
. Any way to avoid it?
sed -i "s#^mac.address.sftp.user.password=.*#mac.address.sftp.user.password=$MacAddressPasswordeRegisteryValue#*=#" $APP_CONFIG_FILE
sed
marked as duplicate by don_crissti, roaima, Rui F Ribeiro, Jeff Schaller, Kusalananda Apr 20 at 15:26
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How to ensure that string interpolated into `sed` substitution escapes all metachars
1 answer
I am using below sed command, but if MacAddressPasswordeRegisteryValue
is WElcome12#
then its producing WElcome12
and removing #
. Any way to avoid it?
sed -i "s#^mac.address.sftp.user.password=.*#mac.address.sftp.user.password=$MacAddressPasswordeRegisteryValue#*=#" $APP_CONFIG_FILE
sed
This question already has an answer here:
How to ensure that string interpolated into `sed` substitution escapes all metachars
1 answer
I am using below sed command, but if MacAddressPasswordeRegisteryValue
is WElcome12#
then its producing WElcome12
and removing #
. Any way to avoid it?
sed -i "s#^mac.address.sftp.user.password=.*#mac.address.sftp.user.password=$MacAddressPasswordeRegisteryValue#*=#" $APP_CONFIG_FILE
This question already has an answer here:
How to ensure that string interpolated into `sed` substitution escapes all metachars
1 answer
sed
edited Apr 19 at 19:55
Kusalananda
102k13199315
102k13199315
asked Apr 19 at 19:54
man
1
1
marked as duplicate by don_crissti, roaima, Rui F Ribeiro, Jeff Schaller, Kusalananda Apr 20 at 15:26
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by don_crissti, roaima, Rui F Ribeiro, Jeff Schaller, Kusalananda Apr 20 at 15:26
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
Assuming the password may contain any character, then no delimiter that you use for the sed
expression is safe to use. If you had, for example, s/.../.../
and the password contained /
, you would have the same issue again.
Therefore, don't use sed
here. Instead,
awk -v pw="$MacAddressPasswordeRegisteryValue"
'BEGIN OFS=FS="="
$1 == "mac.address.sftp.user.password" print $1, pw; next 1'
"$APP_CONFIG_FILE" >"$APP_CONFIG_FILE"-new
This would transform
mac.address.sftp.user.password=something old
into
mac.address.sftp.user.password=hello world !#$/
given that $MacAddressPasswordeRegisteryValue
was the string hello world !#$/
. Other lines would be passed through unmodified to the new file "$APP_CONFIG_FILE"-new
.
Maybe parameter expansion of the variable to escape #?sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
1
@JeffSchaller Consider the passwordhello#
.
â Kusalananda
Apr 19 at 20:17
sed
is perfectly fine here as long as the variable is pre-processed (also viased
@JeffSchaller).
â don_crissti
Apr 19 at 21:58
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Assuming the password may contain any character, then no delimiter that you use for the sed
expression is safe to use. If you had, for example, s/.../.../
and the password contained /
, you would have the same issue again.
Therefore, don't use sed
here. Instead,
awk -v pw="$MacAddressPasswordeRegisteryValue"
'BEGIN OFS=FS="="
$1 == "mac.address.sftp.user.password" print $1, pw; next 1'
"$APP_CONFIG_FILE" >"$APP_CONFIG_FILE"-new
This would transform
mac.address.sftp.user.password=something old
into
mac.address.sftp.user.password=hello world !#$/
given that $MacAddressPasswordeRegisteryValue
was the string hello world !#$/
. Other lines would be passed through unmodified to the new file "$APP_CONFIG_FILE"-new
.
Maybe parameter expansion of the variable to escape #?sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
1
@JeffSchaller Consider the passwordhello#
.
â Kusalananda
Apr 19 at 20:17
sed
is perfectly fine here as long as the variable is pre-processed (also viased
@JeffSchaller).
â don_crissti
Apr 19 at 21:58
add a comment |Â
up vote
1
down vote
Assuming the password may contain any character, then no delimiter that you use for the sed
expression is safe to use. If you had, for example, s/.../.../
and the password contained /
, you would have the same issue again.
Therefore, don't use sed
here. Instead,
awk -v pw="$MacAddressPasswordeRegisteryValue"
'BEGIN OFS=FS="="
$1 == "mac.address.sftp.user.password" print $1, pw; next 1'
"$APP_CONFIG_FILE" >"$APP_CONFIG_FILE"-new
This would transform
mac.address.sftp.user.password=something old
into
mac.address.sftp.user.password=hello world !#$/
given that $MacAddressPasswordeRegisteryValue
was the string hello world !#$/
. Other lines would be passed through unmodified to the new file "$APP_CONFIG_FILE"-new
.
Maybe parameter expansion of the variable to escape #?sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
1
@JeffSchaller Consider the passwordhello#
.
â Kusalananda
Apr 19 at 20:17
sed
is perfectly fine here as long as the variable is pre-processed (also viased
@JeffSchaller).
â don_crissti
Apr 19 at 21:58
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Assuming the password may contain any character, then no delimiter that you use for the sed
expression is safe to use. If you had, for example, s/.../.../
and the password contained /
, you would have the same issue again.
Therefore, don't use sed
here. Instead,
awk -v pw="$MacAddressPasswordeRegisteryValue"
'BEGIN OFS=FS="="
$1 == "mac.address.sftp.user.password" print $1, pw; next 1'
"$APP_CONFIG_FILE" >"$APP_CONFIG_FILE"-new
This would transform
mac.address.sftp.user.password=something old
into
mac.address.sftp.user.password=hello world !#$/
given that $MacAddressPasswordeRegisteryValue
was the string hello world !#$/
. Other lines would be passed through unmodified to the new file "$APP_CONFIG_FILE"-new
.
Assuming the password may contain any character, then no delimiter that you use for the sed
expression is safe to use. If you had, for example, s/.../.../
and the password contained /
, you would have the same issue again.
Therefore, don't use sed
here. Instead,
awk -v pw="$MacAddressPasswordeRegisteryValue"
'BEGIN OFS=FS="="
$1 == "mac.address.sftp.user.password" print $1, pw; next 1'
"$APP_CONFIG_FILE" >"$APP_CONFIG_FILE"-new
This would transform
mac.address.sftp.user.password=something old
into
mac.address.sftp.user.password=hello world !#$/
given that $MacAddressPasswordeRegisteryValue
was the string hello world !#$/
. Other lines would be passed through unmodified to the new file "$APP_CONFIG_FILE"-new
.
answered Apr 19 at 20:05
Kusalananda
102k13199315
102k13199315
Maybe parameter expansion of the variable to escape #?sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
1
@JeffSchaller Consider the passwordhello#
.
â Kusalananda
Apr 19 at 20:17
sed
is perfectly fine here as long as the variable is pre-processed (also viased
@JeffSchaller).
â don_crissti
Apr 19 at 21:58
add a comment |Â
Maybe parameter expansion of the variable to escape #?sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
1
@JeffSchaller Consider the passwordhello#
.
â Kusalananda
Apr 19 at 20:17
sed
is perfectly fine here as long as the variable is pre-processed (also viased
@JeffSchaller).
â don_crissti
Apr 19 at 21:58
Maybe parameter expansion of the variable to escape #?
sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
Maybe parameter expansion of the variable to escape #?
sed âÂÂs#foo#$var//#\##âÂÂ
â Jeff Schaller
Apr 19 at 20:15
1
1
@JeffSchaller Consider the password
hello#
.â Kusalananda
Apr 19 at 20:17
@JeffSchaller Consider the password
hello#
.â Kusalananda
Apr 19 at 20:17
sed
is perfectly fine here as long as the variable is pre-processed (also via sed
@JeffSchaller).â don_crissti
Apr 19 at 21:58
sed
is perfectly fine here as long as the variable is pre-processed (also via sed
@JeffSchaller).â don_crissti
Apr 19 at 21:58
add a comment |Â