Replacing [0-9] with [A-J] not working with sed

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.



The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt



It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"










share|improve this question







New contributor




Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    2
    down vote

    favorite












    I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.



    The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt



    It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"










    share|improve this question







    New contributor




    Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.



      The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt



      It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"










      share|improve this question







      New contributor




      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.



      The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt



      It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"







      linux command-line bash regex sed






      share|improve this question







      New contributor




      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      Matthew Snell

      111




      111




      New contributor




      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Matthew Snell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          You want transliteration, not substitution, so replace s with y:



          echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'


          sed can't use ranges in y, but Perl can:



          echo 34031445 | perl -pe 'y/0-9/A-J/'


          Or just use tr:



          echo 34031445 | tr 0-9 A-J





          share|improve this answer




















          • Agreed. tr is the easiest and probably the fastest tool for the job.
            – sdkks
            21 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "3"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1368784%2freplacing-0-9-with-a-j-not-working-with-sed%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote













          You want transliteration, not substitution, so replace s with y:



          echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'


          sed can't use ranges in y, but Perl can:



          echo 34031445 | perl -pe 'y/0-9/A-J/'


          Or just use tr:



          echo 34031445 | tr 0-9 A-J





          share|improve this answer




















          • Agreed. tr is the easiest and probably the fastest tool for the job.
            – sdkks
            21 mins ago














          up vote
          3
          down vote













          You want transliteration, not substitution, so replace s with y:



          echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'


          sed can't use ranges in y, but Perl can:



          echo 34031445 | perl -pe 'y/0-9/A-J/'


          Or just use tr:



          echo 34031445 | tr 0-9 A-J





          share|improve this answer




















          • Agreed. tr is the easiest and probably the fastest tool for the job.
            – sdkks
            21 mins ago












          up vote
          3
          down vote










          up vote
          3
          down vote









          You want transliteration, not substitution, so replace s with y:



          echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'


          sed can't use ranges in y, but Perl can:



          echo 34031445 | perl -pe 'y/0-9/A-J/'


          Or just use tr:



          echo 34031445 | tr 0-9 A-J





          share|improve this answer












          You want transliteration, not substitution, so replace s with y:



          echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'


          sed can't use ranges in y, but Perl can:



          echo 34031445 | perl -pe 'y/0-9/A-J/'


          Or just use tr:



          echo 34031445 | tr 0-9 A-J






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          choroba

          12.5k12838




          12.5k12838











          • Agreed. tr is the easiest and probably the fastest tool for the job.
            – sdkks
            21 mins ago
















          • Agreed. tr is the easiest and probably the fastest tool for the job.
            – sdkks
            21 mins ago















          Agreed. tr is the easiest and probably the fastest tool for the job.
          – sdkks
          21 mins ago




          Agreed. tr is the easiest and probably the fastest tool for the job.
          – sdkks
          21 mins ago










          Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.












          Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.











          Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1368784%2freplacing-0-9-with-a-j-not-working-with-sed%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke