Can I run two different awk commands in 1











up vote
0
down vote

favorite












I can use this awk command to get last line of log file:



awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log


And I can use this awk command to extract a substring:



awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log


What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?



Last line in log file always has string I need:



[2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"


The part in parenthesis is what I want.
Resulting output:



Canada Vancouver









share|improve this question




























    up vote
    0
    down vote

    favorite












    I can use this awk command to get last line of log file:



    awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log


    And I can use this awk command to extract a substring:



    awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log


    What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?



    Last line in log file always has string I need:



    [2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"


    The part in parenthesis is what I want.
    Resulting output:



    Canada Vancouver









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I can use this awk command to get last line of log file:



      awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log


      And I can use this awk command to extract a substring:



      awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log


      What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?



      Last line in log file always has string I need:



      [2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"


      The part in parenthesis is what I want.
      Resulting output:



      Canada Vancouver









      share|improve this question















      I can use this awk command to get last line of log file:



      awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log


      And I can use this awk command to extract a substring:



      awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log


      What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?



      Last line in log file always has string I need:



      [2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"


      The part in parenthesis is what I want.
      Resulting output:



      Canada Vancouver






      command-line text-processing awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      muru

      133k19282479




      133k19282479










      asked Nov 15 at 6:44









      jj1

      115




      115






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          If you want the second field of the last line using that field separator:



          awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log





          share|improve this answer





















          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            2 days ago




















          up vote
          0
          down vote













          Pipe the output of the first awk to the second awk:



          awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'


          This variant is more safe (ignore last empty lines in file):



          awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'





          share|improve this answer























          • @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
            – jj1
            Nov 15 at 7:14










          • The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
            – jj1
            Nov 15 at 7:24










          • Yes, last non empty line. Also fixed second example containing your previous comment
            – S_Flash
            2 days ago













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          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: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1093075%2fcan-i-run-two-different-awk-commands-in-1%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








          up vote
          1
          down vote













          If you want the second field of the last line using that field separator:



          awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log





          share|improve this answer





















          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            2 days ago

















          up vote
          1
          down vote













          If you want the second field of the last line using that field separator:



          awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log





          share|improve this answer





















          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            2 days ago















          up vote
          1
          down vote










          up vote
          1
          down vote









          If you want the second field of the last line using that field separator:



          awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log





          share|improve this answer












          If you want the second field of the last line using that field separator:



          awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          muru

          133k19282479




          133k19282479












          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            2 days ago




















          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            2 days ago


















          muru Thank you for your solution. It's exactly what I was after.
          – jj1
          2 days ago






          muru Thank you for your solution. It's exactly what I was after.
          – jj1
          2 days ago














          up vote
          0
          down vote













          Pipe the output of the first awk to the second awk:



          awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'


          This variant is more safe (ignore last empty lines in file):



          awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'





          share|improve this answer























          • @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
            – jj1
            Nov 15 at 7:14










          • The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
            – jj1
            Nov 15 at 7:24










          • Yes, last non empty line. Also fixed second example containing your previous comment
            – S_Flash
            2 days ago

















          up vote
          0
          down vote













          Pipe the output of the first awk to the second awk:



          awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'


          This variant is more safe (ignore last empty lines in file):



          awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'





          share|improve this answer























          • @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
            – jj1
            Nov 15 at 7:14










          • The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
            – jj1
            Nov 15 at 7:24










          • Yes, last non empty line. Also fixed second example containing your previous comment
            – S_Flash
            2 days ago















          up vote
          0
          down vote










          up vote
          0
          down vote









          Pipe the output of the first awk to the second awk:



          awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'


          This variant is more safe (ignore last empty lines in file):



          awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'





          share|improve this answer














          Pipe the output of the first awk to the second awk:



          awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'


          This variant is more safe (ignore last empty lines in file):



          awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered Nov 15 at 6:55









          S_Flash

          858117




          858117












          • @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
            – jj1
            Nov 15 at 7:14










          • The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
            – jj1
            Nov 15 at 7:24










          • Yes, last non empty line. Also fixed second example containing your previous comment
            – S_Flash
            2 days ago




















          • @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
            – jj1
            Nov 15 at 7:14










          • The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
            – jj1
            Nov 15 at 7:24










          • Yes, last non empty line. Also fixed second example containing your previous comment
            – S_Flash
            2 days ago


















          @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
          – jj1
          Nov 15 at 7:14




          @ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
          – jj1
          Nov 15 at 7:14












          The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
          – jj1
          Nov 15 at 7:24




          The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
          – jj1
          Nov 15 at 7:24












          Yes, last non empty line. Also fixed second example containing your previous comment
          – S_Flash
          2 days ago






          Yes, last non empty line. Also fixed second example containing your previous comment
          – S_Flash
          2 days ago




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1093075%2fcan-i-run-two-different-awk-commands-in-1%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

          Ellipse (mathématiques)

          Quarter-circle Tiles

          Mont Emei