sed コマンドの削除# [重複]

sed コマンドの削除# [重複]

以下ではsedコマンドを使用していますが、ifはbuildとdeleteMacAddressPasswordeRegisteryValueです。これを避ける方法はありますか?WElcome12#WElcome12#

sed -i "s#^mac.address.sftp.user.password=.*#mac.address.sftp.user.password=${MacAddressPasswordeRegisteryValue#*=}#" $APP_CONFIG_FILE

ベストアンサー1

パスワードに文字を含めることができると仮定すると、式で使用されている区切り文字はsed安全には使用できません。たとえば、s/.../.../パスワードにが含まれている場合、/同じ問題が再発生します。

したがって、sedここでは使用しないでください。代わりに、

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

これは変わるでしょう

mac.address.sftp.user.password=something old

入力する

mac.address.sftp.user.password=hello world !#$/

それが$MacAddressPasswordeRegisteryValue文字列であればhello world !#$/。他の行は変更なしで新しいファイルに渡されます"$APP_CONFIG_FILE"-new

おすすめ記事