How to keep colored output using sed












8















I'm using the sed command and I want to keep colored output from the previous command. The output of ls is colored, but the output of sed is not. I'm using OSX.



ls -la | sed -En  '/Desktop/q;p'









share|improve this question









New contributor




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

























    8















    I'm using the sed command and I want to keep colored output from the previous command. The output of ls is colored, but the output of sed is not. I'm using OSX.



    ls -la | sed -En  '/Desktop/q;p'









    share|improve this question









    New contributor




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























      8












      8








      8


      3






      I'm using the sed command and I want to keep colored output from the previous command. The output of ls is colored, but the output of sed is not. I'm using OSX.



      ls -la | sed -En  '/Desktop/q;p'









      share|improve this question









      New contributor




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












      I'm using the sed command and I want to keep colored output from the previous command. The output of ls is colored, but the output of sed is not. I'm using OSX.



      ls -la | sed -En  '/Desktop/q;p'






      sed osx pipe ls colors






      share|improve this question









      New contributor




      Johniak 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




      Johniak 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








      edited yesterday









      Jeff Schaller

      40.6k1056129




      40.6k1056129






      New contributor




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









      asked yesterday









      JohniakJohniak

      1411




      1411




      New contributor




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





      New contributor





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






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






















          2 Answers
          2






          active

          oldest

          votes


















          12














          On macOS, the ls is not GNU ls and does not accept the --color=always option that Linux users might expect for this functionality.



          In the macOS version of ls, the colors are controlled by two variables: $CLICOLOR and $CLICOLOR_FORCE. If the former is defined, the terminal specified by $TERM supports color, and the output is to a terminal, then this output will be colored, much like GNU's --color=auto option. If the latter variable is defined as well, the final condition is dropped, behaving like GNU's --color=always.



          So to have color passed through to sed, you would need something like the following:



          CLICOLOR_FORCE=1 ls -la | sed -En '/Desktop/q;p'





          share|improve this answer


























          • macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

            – 8bittree
            yesterday






          • 2





            @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

            – Fox
            yesterday



















          6














          I'll blindly guess that your distribution, like many, has an alias that maps ls to ls --color=auto. ls -la --color=always | sed … should work.



          (The auto setting makes, broadly speaking, ls check if its output goes to the display or not, and only color for the display. The reason for this is that color is realized by escape sequences, i.e. invisible command characters, so a program might confuse them for part of the filename, things like that.)






          share|improve this answer



















          • 3





            The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

            – Fox
            yesterday











          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Johniak 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%2funix.stackexchange.com%2fquestions%2f497413%2fhow-to-keep-colored-output-using-sed%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          12














          On macOS, the ls is not GNU ls and does not accept the --color=always option that Linux users might expect for this functionality.



          In the macOS version of ls, the colors are controlled by two variables: $CLICOLOR and $CLICOLOR_FORCE. If the former is defined, the terminal specified by $TERM supports color, and the output is to a terminal, then this output will be colored, much like GNU's --color=auto option. If the latter variable is defined as well, the final condition is dropped, behaving like GNU's --color=always.



          So to have color passed through to sed, you would need something like the following:



          CLICOLOR_FORCE=1 ls -la | sed -En '/Desktop/q;p'





          share|improve this answer


























          • macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

            – 8bittree
            yesterday






          • 2





            @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

            – Fox
            yesterday
















          12














          On macOS, the ls is not GNU ls and does not accept the --color=always option that Linux users might expect for this functionality.



          In the macOS version of ls, the colors are controlled by two variables: $CLICOLOR and $CLICOLOR_FORCE. If the former is defined, the terminal specified by $TERM supports color, and the output is to a terminal, then this output will be colored, much like GNU's --color=auto option. If the latter variable is defined as well, the final condition is dropped, behaving like GNU's --color=always.



          So to have color passed through to sed, you would need something like the following:



          CLICOLOR_FORCE=1 ls -la | sed -En '/Desktop/q;p'





          share|improve this answer


























          • macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

            – 8bittree
            yesterday






          • 2





            @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

            – Fox
            yesterday














          12












          12








          12







          On macOS, the ls is not GNU ls and does not accept the --color=always option that Linux users might expect for this functionality.



          In the macOS version of ls, the colors are controlled by two variables: $CLICOLOR and $CLICOLOR_FORCE. If the former is defined, the terminal specified by $TERM supports color, and the output is to a terminal, then this output will be colored, much like GNU's --color=auto option. If the latter variable is defined as well, the final condition is dropped, behaving like GNU's --color=always.



          So to have color passed through to sed, you would need something like the following:



          CLICOLOR_FORCE=1 ls -la | sed -En '/Desktop/q;p'





          share|improve this answer















          On macOS, the ls is not GNU ls and does not accept the --color=always option that Linux users might expect for this functionality.



          In the macOS version of ls, the colors are controlled by two variables: $CLICOLOR and $CLICOLOR_FORCE. If the former is defined, the terminal specified by $TERM supports color, and the output is to a terminal, then this output will be colored, much like GNU's --color=auto option. If the latter variable is defined as well, the final condition is dropped, behaving like GNU's --color=always.



          So to have color passed through to sed, you would need something like the following:



          CLICOLOR_FORCE=1 ls -la | sed -En '/Desktop/q;p'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday









          terdon

          130k32254432




          130k32254432










          answered yesterday









          FoxFox

          5,44911233




          5,44911233













          • macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

            – 8bittree
            yesterday






          • 2





            @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

            – Fox
            yesterday



















          • macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

            – 8bittree
            yesterday






          • 2





            @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

            – Fox
            yesterday

















          macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

          – 8bittree
          yesterday





          macOS's ls does have the -G option to enable color as well, but I'm not sure how it behaves in a pipeline.

          – 8bittree
          yesterday




          2




          2





          @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

          – Fox
          yesterday





          @8bittree Passing -G is equivalent to defining $CLICOLOR (and therefore not sufficient)

          – Fox
          yesterday













          6














          I'll blindly guess that your distribution, like many, has an alias that maps ls to ls --color=auto. ls -la --color=always | sed … should work.



          (The auto setting makes, broadly speaking, ls check if its output goes to the display or not, and only color for the display. The reason for this is that color is realized by escape sequences, i.e. invisible command characters, so a program might confuse them for part of the filename, things like that.)






          share|improve this answer



















          • 3





            The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

            – Fox
            yesterday
















          6














          I'll blindly guess that your distribution, like many, has an alias that maps ls to ls --color=auto. ls -la --color=always | sed … should work.



          (The auto setting makes, broadly speaking, ls check if its output goes to the display or not, and only color for the display. The reason for this is that color is realized by escape sequences, i.e. invisible command characters, so a program might confuse them for part of the filename, things like that.)






          share|improve this answer



















          • 3





            The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

            – Fox
            yesterday














          6












          6








          6







          I'll blindly guess that your distribution, like many, has an alias that maps ls to ls --color=auto. ls -la --color=always | sed … should work.



          (The auto setting makes, broadly speaking, ls check if its output goes to the display or not, and only color for the display. The reason for this is that color is realized by escape sequences, i.e. invisible command characters, so a program might confuse them for part of the filename, things like that.)






          share|improve this answer













          I'll blindly guess that your distribution, like many, has an alias that maps ls to ls --color=auto. ls -la --color=always | sed … should work.



          (The auto setting makes, broadly speaking, ls check if its output goes to the display or not, and only color for the display. The reason for this is that color is realized by escape sequences, i.e. invisible command characters, so a program might confuse them for part of the filename, things like that.)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Ulrich SchwarzUlrich Schwarz

          9,74312946




          9,74312946








          • 3





            The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

            – Fox
            yesterday














          • 3





            The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

            – Fox
            yesterday








          3




          3





          The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

          – Fox
          yesterday





          The blind guess is wrong. OSX is not a Linux distribution and does not use a GNU userland

          – Fox
          yesterday










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










          draft saved

          draft discarded


















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













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












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
















          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497413%2fhow-to-keep-colored-output-using-sed%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]