sed command removing # [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash 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






share|improve this 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.


















    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






    share|improve this 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.
















      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






      share|improve this question














      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









      share|improve this question












      share|improve this question




      share|improve this question








      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.






















          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.






          share|improve this answer





















          • Maybe parameter expansion of the variable to escape #? sed “s#foo#$var//#\##”
            – Jeff Schaller
            Apr 19 at 20:15






          • 1




            @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


















          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.






          share|improve this answer





















          • Maybe parameter expansion of the variable to escape #? sed “s#foo#$var//#\##”
            – Jeff Schaller
            Apr 19 at 20:15






          • 1




            @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















          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.






          share|improve this answer





















          • Maybe parameter expansion of the variable to escape #? sed “s#foo#$var//#\##”
            – Jeff Schaller
            Apr 19 at 20:15






          • 1




            @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













          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.






          share|improve this answer













          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.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          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 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

















          • Maybe parameter expansion of the variable to escape #? sed “s#foo#$var//#\##”
            – Jeff Schaller
            Apr 19 at 20:15






          • 1




            @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
















          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



          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?