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 Nov 15 at 12:59









      muru

      134k19282482




      134k19282482










      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
            Nov 15 at 12:57




















          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
            Nov 15 at 8:05













          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
            Nov 15 at 12:57

















          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
            Nov 15 at 12:57















          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 Nov 15 at 7:34









          muru

          134k19282482




          134k19282482












          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            Nov 15 at 12:57




















          • muru Thank you for your solution. It's exactly what I was after.
            – jj1
            Nov 15 at 12:57


















          muru Thank you for your solution. It's exactly what I was after.
          – jj1
          Nov 15 at 12:57






          muru Thank you for your solution. It's exactly what I was after.
          – jj1
          Nov 15 at 12:57














          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
            Nov 15 at 8:05

















          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
            Nov 15 at 8:05















          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 Nov 15 at 8:04

























          answered Nov 15 at 6:55









          S_Flash

          928117




          928117












          • @ 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
            Nov 15 at 8:05




















          • @ 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
            Nov 15 at 8:05


















          @ 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
          Nov 15 at 8:05






          Yes, last non empty line. Also fixed second example containing your previous comment
          – S_Flash
          Nov 15 at 8:05




















           

          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

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?