Logging only a specific part of stderr?

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











up vote
1
down vote

favorite












Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example



Running tar -xzf file 2>> log.txt, and getting an error



tar: Child returned status 1


I only want to log the Child returned status 1 part, and not include the command name.










share|improve this question



















  • 1




    You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
    – thrig
    Oct 2 '17 at 14:15










  • Do you want to remove the tar: prefix off every error message by tar, or just that one and discard every other error message by both tar and gzip?
    – Stéphane Chazelas
    Oct 2 '17 at 22:10














up vote
1
down vote

favorite












Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example



Running tar -xzf file 2>> log.txt, and getting an error



tar: Child returned status 1


I only want to log the Child returned status 1 part, and not include the command name.










share|improve this question



















  • 1




    You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
    – thrig
    Oct 2 '17 at 14:15










  • Do you want to remove the tar: prefix off every error message by tar, or just that one and discard every other error message by both tar and gzip?
    – Stéphane Chazelas
    Oct 2 '17 at 22:10












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example



Running tar -xzf file 2>> log.txt, and getting an error



tar: Child returned status 1


I only want to log the Child returned status 1 part, and not include the command name.










share|improve this question















Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example



Running tar -xzf file 2>> log.txt, and getting an error



tar: Child returned status 1


I only want to log the Child returned status 1 part, and not include the command name.







stderr






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 2 '17 at 20:39









Hauke Laging

53.7k1282130




53.7k1282130










asked Oct 2 '17 at 4:57









Hanson Duan

61




61







  • 1




    You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
    – thrig
    Oct 2 '17 at 14:15










  • Do you want to remove the tar: prefix off every error message by tar, or just that one and discard every other error message by both tar and gzip?
    – Stéphane Chazelas
    Oct 2 '17 at 22:10












  • 1




    You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
    – thrig
    Oct 2 '17 at 14:15










  • Do you want to remove the tar: prefix off every error message by tar, or just that one and discard every other error message by both tar and gzip?
    – Stéphane Chazelas
    Oct 2 '17 at 22:10







1




1




You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
– thrig
Oct 2 '17 at 14:15




You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
– thrig
Oct 2 '17 at 14:15












Do you want to remove the tar: prefix off every error message by tar, or just that one and discard every other error message by both tar and gzip?
– Stéphane Chazelas
Oct 2 '17 at 22:10




Do you want to remove the tar: prefix off every error message by tar, or just that one and discard every other error message by both tar and gzip?
– Stéphane Chazelas
Oct 2 '17 at 22:10










2 Answers
2






active

oldest

votes

















up vote
0
down vote













tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile





share|improve this answer



























    up vote
    0
    down vote













    With zsh, you can do:



    tar -xzf file 2> >(sed 's/^tar: //' >> file.log)


    Which allows to retain tar's exit status.



    You can do something similar with ksh, bash or yash though you'd have to use work arounds there to make sure sed has finished by the time you run the next command if that command makes use of the file.log.



    Other option with bash is to use:



     sed 's/^tar: //' >> file.log 3>&-; 3>&1
    tar_exit_status=$PIPESTATUS[0]


    Note that with several shells, you can also call tar with an empty argv[0] with:



    (exec -a '' tar -xzf file)


    In which case the error messages will look like:



    : Child returned status 1





    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%2f395562%2flogging-only-a-specific-part-of-stderr%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
      0
      down vote













      tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile





      share|improve this answer
























        up vote
        0
        down vote













        tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile





        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile





          share|improve this answer












          tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 2 '17 at 20:38









          Hauke Laging

          53.7k1282130




          53.7k1282130






















              up vote
              0
              down vote













              With zsh, you can do:



              tar -xzf file 2> >(sed 's/^tar: //' >> file.log)


              Which allows to retain tar's exit status.



              You can do something similar with ksh, bash or yash though you'd have to use work arounds there to make sure sed has finished by the time you run the next command if that command makes use of the file.log.



              Other option with bash is to use:



               sed 's/^tar: //' >> file.log 3>&-; 3>&1
              tar_exit_status=$PIPESTATUS[0]


              Note that with several shells, you can also call tar with an empty argv[0] with:



              (exec -a '' tar -xzf file)


              In which case the error messages will look like:



              : Child returned status 1





              share|improve this answer
























                up vote
                0
                down vote













                With zsh, you can do:



                tar -xzf file 2> >(sed 's/^tar: //' >> file.log)


                Which allows to retain tar's exit status.



                You can do something similar with ksh, bash or yash though you'd have to use work arounds there to make sure sed has finished by the time you run the next command if that command makes use of the file.log.



                Other option with bash is to use:



                 sed 's/^tar: //' >> file.log 3>&-; 3>&1
                tar_exit_status=$PIPESTATUS[0]


                Note that with several shells, you can also call tar with an empty argv[0] with:



                (exec -a '' tar -xzf file)


                In which case the error messages will look like:



                : Child returned status 1





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  With zsh, you can do:



                  tar -xzf file 2> >(sed 's/^tar: //' >> file.log)


                  Which allows to retain tar's exit status.



                  You can do something similar with ksh, bash or yash though you'd have to use work arounds there to make sure sed has finished by the time you run the next command if that command makes use of the file.log.



                  Other option with bash is to use:



                   sed 's/^tar: //' >> file.log 3>&-; 3>&1
                  tar_exit_status=$PIPESTATUS[0]


                  Note that with several shells, you can also call tar with an empty argv[0] with:



                  (exec -a '' tar -xzf file)


                  In which case the error messages will look like:



                  : Child returned status 1





                  share|improve this answer












                  With zsh, you can do:



                  tar -xzf file 2> >(sed 's/^tar: //' >> file.log)


                  Which allows to retain tar's exit status.



                  You can do something similar with ksh, bash or yash though you'd have to use work arounds there to make sure sed has finished by the time you run the next command if that command makes use of the file.log.



                  Other option with bash is to use:



                   sed 's/^tar: //' >> file.log 3>&-; 3>&1
                  tar_exit_status=$PIPESTATUS[0]


                  Note that with several shells, you can also call tar with an empty argv[0] with:



                  (exec -a '' tar -xzf file)


                  In which case the error messages will look like:



                  : Child returned status 1






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 2 '17 at 22:22









                  Stéphane Chazelas

                  283k53522859




                  283k53522859



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395562%2flogging-only-a-specific-part-of-stderr%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?