Replacing same keyword with different strings per line

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











up vote
1
down vote

favorite












I'm using the following command to return a list of available disks and whether they're ssd or rotational (basically replacing 0 and 1 in lsblk's output with their actual meaning):



lsblk -d -o name,ro | sed "s/RO/ TYPE/; s/NAME/DISK/; s/0/SSD/g; s/1/ROT/g"


sample output:



DISK TYPE
sda SSD
sdb ROT


Now I'd like to add another column, "rm", to lsblk (lsblk -d -o name,ro,rm) but it also uses 0 and 1 to mean a different thing (0=fixed disk, 1=removable).



Is there a way to use sed (or awk or anything else) to replace 0 and 1's in the third column with YES and NO?







share|improve this question

























    up vote
    1
    down vote

    favorite












    I'm using the following command to return a list of available disks and whether they're ssd or rotational (basically replacing 0 and 1 in lsblk's output with their actual meaning):



    lsblk -d -o name,ro | sed "s/RO/ TYPE/; s/NAME/DISK/; s/0/SSD/g; s/1/ROT/g"


    sample output:



    DISK TYPE
    sda SSD
    sdb ROT


    Now I'd like to add another column, "rm", to lsblk (lsblk -d -o name,ro,rm) but it also uses 0 and 1 to mean a different thing (0=fixed disk, 1=removable).



    Is there a way to use sed (or awk or anything else) to replace 0 and 1's in the third column with YES and NO?







    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm using the following command to return a list of available disks and whether they're ssd or rotational (basically replacing 0 and 1 in lsblk's output with their actual meaning):



      lsblk -d -o name,ro | sed "s/RO/ TYPE/; s/NAME/DISK/; s/0/SSD/g; s/1/ROT/g"


      sample output:



      DISK TYPE
      sda SSD
      sdb ROT


      Now I'd like to add another column, "rm", to lsblk (lsblk -d -o name,ro,rm) but it also uses 0 and 1 to mean a different thing (0=fixed disk, 1=removable).



      Is there a way to use sed (or awk or anything else) to replace 0 and 1's in the third column with YES and NO?







      share|improve this question













      I'm using the following command to return a list of available disks and whether they're ssd or rotational (basically replacing 0 and 1 in lsblk's output with their actual meaning):



      lsblk -d -o name,ro | sed "s/RO/ TYPE/; s/NAME/DISK/; s/0/SSD/g; s/1/ROT/g"


      sample output:



      DISK TYPE
      sda SSD
      sdb ROT


      Now I'd like to add another column, "rm", to lsblk (lsblk -d -o name,ro,rm) but it also uses 0 and 1 to mean a different thing (0=fixed disk, 1=removable).



      Is there a way to use sed (or awk or anything else) to replace 0 and 1's in the third column with YES and NO?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 3 at 13:56









      Jeff Schaller

      30.8k846104




      30.8k846104









      asked Jul 3 at 13:47









      Mark Roi

      448




      448




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Awk approach:



          lsblk -d -o name,ro,rm 
          | awk 'NR == 1 print "DISK TYPE REMOVABLE"; split("SSD ROT", ro); split("NO YES", rm); next
          print $1, ro[$2+1], rm[$3+1] '


          Sample output:



          DISK TYPE REMOVABLE
          sda SSD NO
          sr0 SSD YES





          share|improve this answer





















          • Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
            – Mark Roi
            Jul 4 at 13:20











          • @MarkRoi, you're welcome
            – RomanPerekhrest
            Jul 4 at 13:36

















          up vote
          3
          down vote













          try



          lsblk -d -o name,ro,rm |
          awk '$2 == 0 $2 = "SSD" ; $2 == 1 $2 = "ROT" ;
          $3 == 0 $3 = "NO" ; $3 == 1 $3 = "YES" ;
          print ; '


          • this can be one-lined.

          • sometime people use 1 instead of print ; .

          • changing RO to TYPE is left as an exercice.





          share|improve this answer





















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453227%2freplacing-same-keyword-with-different-strings-per-line%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            Awk approach:



            lsblk -d -o name,ro,rm 
            | awk 'NR == 1 print "DISK TYPE REMOVABLE"; split("SSD ROT", ro); split("NO YES", rm); next
            print $1, ro[$2+1], rm[$3+1] '


            Sample output:



            DISK TYPE REMOVABLE
            sda SSD NO
            sr0 SSD YES





            share|improve this answer





















            • Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
              – Mark Roi
              Jul 4 at 13:20











            • @MarkRoi, you're welcome
              – RomanPerekhrest
              Jul 4 at 13:36














            up vote
            2
            down vote



            accepted










            Awk approach:



            lsblk -d -o name,ro,rm 
            | awk 'NR == 1 print "DISK TYPE REMOVABLE"; split("SSD ROT", ro); split("NO YES", rm); next
            print $1, ro[$2+1], rm[$3+1] '


            Sample output:



            DISK TYPE REMOVABLE
            sda SSD NO
            sr0 SSD YES





            share|improve this answer





















            • Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
              – Mark Roi
              Jul 4 at 13:20











            • @MarkRoi, you're welcome
              – RomanPerekhrest
              Jul 4 at 13:36












            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            Awk approach:



            lsblk -d -o name,ro,rm 
            | awk 'NR == 1 print "DISK TYPE REMOVABLE"; split("SSD ROT", ro); split("NO YES", rm); next
            print $1, ro[$2+1], rm[$3+1] '


            Sample output:



            DISK TYPE REMOVABLE
            sda SSD NO
            sr0 SSD YES





            share|improve this answer













            Awk approach:



            lsblk -d -o name,ro,rm 
            | awk 'NR == 1 print "DISK TYPE REMOVABLE"; split("SSD ROT", ro); split("NO YES", rm); next
            print $1, ro[$2+1], rm[$3+1] '


            Sample output:



            DISK TYPE REMOVABLE
            sda SSD NO
            sr0 SSD YES






            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Jul 3 at 14:32









            RomanPerekhrest

            22.4k12144




            22.4k12144











            • Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
              – Mark Roi
              Jul 4 at 13:20











            • @MarkRoi, you're welcome
              – RomanPerekhrest
              Jul 4 at 13:36
















            • Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
              – Mark Roi
              Jul 4 at 13:20











            • @MarkRoi, you're welcome
              – RomanPerekhrest
              Jul 4 at 13:36















            Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
            – Mark Roi
            Jul 4 at 13:20





            Both answers valid, but choosing this one for the smarter approach (didn't know about split). Thanks!
            – Mark Roi
            Jul 4 at 13:20













            @MarkRoi, you're welcome
            – RomanPerekhrest
            Jul 4 at 13:36




            @MarkRoi, you're welcome
            – RomanPerekhrest
            Jul 4 at 13:36












            up vote
            3
            down vote













            try



            lsblk -d -o name,ro,rm |
            awk '$2 == 0 $2 = "SSD" ; $2 == 1 $2 = "ROT" ;
            $3 == 0 $3 = "NO" ; $3 == 1 $3 = "YES" ;
            print ; '


            • this can be one-lined.

            • sometime people use 1 instead of print ; .

            • changing RO to TYPE is left as an exercice.





            share|improve this answer

























              up vote
              3
              down vote













              try



              lsblk -d -o name,ro,rm |
              awk '$2 == 0 $2 = "SSD" ; $2 == 1 $2 = "ROT" ;
              $3 == 0 $3 = "NO" ; $3 == 1 $3 = "YES" ;
              print ; '


              • this can be one-lined.

              • sometime people use 1 instead of print ; .

              • changing RO to TYPE is left as an exercice.





              share|improve this answer























                up vote
                3
                down vote










                up vote
                3
                down vote









                try



                lsblk -d -o name,ro,rm |
                awk '$2 == 0 $2 = "SSD" ; $2 == 1 $2 = "ROT" ;
                $3 == 0 $3 = "NO" ; $3 == 1 $3 = "YES" ;
                print ; '


                • this can be one-lined.

                • sometime people use 1 instead of print ; .

                • changing RO to TYPE is left as an exercice.





                share|improve this answer













                try



                lsblk -d -o name,ro,rm |
                awk '$2 == 0 $2 = "SSD" ; $2 == 1 $2 = "ROT" ;
                $3 == 0 $3 = "NO" ; $3 == 1 $3 = "YES" ;
                print ; '


                • this can be one-lined.

                • sometime people use 1 instead of print ; .

                • changing RO to TYPE is left as an exercice.






                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jul 3 at 14:03









                Archemar

                18.9k93365




                18.9k93365






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453227%2freplacing-same-keyword-with-different-strings-per-line%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    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?