How to get the second column from command output?











up vote
2
down vote

favorite












My command's output is something like:



                                   N O D E   O U T P U T

THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET NSET_OUTPUT

NODE FOOT- NT11
NOTE

3 20.00
11 20.00
1003 23.75
1011 23.75
2003 27.52
2011 27.52
3003 31.30
3011 31.30
4003 35.08
4011 35.08
5003 38.87
5011 38.87
6003 42.67
6011 42.67
7003 46.48
7011 46.48
8003 50.29
8011 50.29
9003 54.12
9011 54.12
10003 57.95
10011 57.95
11003 61.79
11011 61.79
12003 65.64
12011 65.64
13003 69.50
13011 69.50
14003 73.37
14011 73.37
15003 77.25
15011 77.25
16003 81.14


The first column is always a number,My purpose is to get the second column only, like:



20.00
20.00
23.75
23.75
27.52
27.52
31.30
31.30
.
.


I intended to use



# gawk -f nset_output.awk electric_thermal.dat
BEGIN{
}
{
if($12~/NSET_OUTPUT/ ){
for(i=1;i <= 5; i++){
getline
}
x=$2

print x >"nset_output.dat"

}

}


to accomplish this.but,the output is messed up: (only one value 20.00)
20.00



So,How do I get the second column's value? (in my case I have 405 rows corresponding 405 values with 1 column)










share|improve this question
















bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • If the header is fixed-length, you could remove it with just tail, and then awk for the other column. I'd suggest taking some care in indenting code, the snippet in the question is quite hard to interpret since the indentation and the braces do not match.
    – ilkkachu
    Aug 3 '16 at 14:24















up vote
2
down vote

favorite












My command's output is something like:



                                   N O D E   O U T P U T

THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET NSET_OUTPUT

NODE FOOT- NT11
NOTE

3 20.00
11 20.00
1003 23.75
1011 23.75
2003 27.52
2011 27.52
3003 31.30
3011 31.30
4003 35.08
4011 35.08
5003 38.87
5011 38.87
6003 42.67
6011 42.67
7003 46.48
7011 46.48
8003 50.29
8011 50.29
9003 54.12
9011 54.12
10003 57.95
10011 57.95
11003 61.79
11011 61.79
12003 65.64
12011 65.64
13003 69.50
13011 69.50
14003 73.37
14011 73.37
15003 77.25
15011 77.25
16003 81.14


The first column is always a number,My purpose is to get the second column only, like:



20.00
20.00
23.75
23.75
27.52
27.52
31.30
31.30
.
.


I intended to use



# gawk -f nset_output.awk electric_thermal.dat
BEGIN{
}
{
if($12~/NSET_OUTPUT/ ){
for(i=1;i <= 5; i++){
getline
}
x=$2

print x >"nset_output.dat"

}

}


to accomplish this.but,the output is messed up: (only one value 20.00)
20.00



So,How do I get the second column's value? (in my case I have 405 rows corresponding 405 values with 1 column)










share|improve this question
















bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • If the header is fixed-length, you could remove it with just tail, and then awk for the other column. I'd suggest taking some care in indenting code, the snippet in the question is quite hard to interpret since the indentation and the braces do not match.
    – ilkkachu
    Aug 3 '16 at 14:24













up vote
2
down vote

favorite









up vote
2
down vote

favorite











My command's output is something like:



                                   N O D E   O U T P U T

THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET NSET_OUTPUT

NODE FOOT- NT11
NOTE

3 20.00
11 20.00
1003 23.75
1011 23.75
2003 27.52
2011 27.52
3003 31.30
3011 31.30
4003 35.08
4011 35.08
5003 38.87
5011 38.87
6003 42.67
6011 42.67
7003 46.48
7011 46.48
8003 50.29
8011 50.29
9003 54.12
9011 54.12
10003 57.95
10011 57.95
11003 61.79
11011 61.79
12003 65.64
12011 65.64
13003 69.50
13011 69.50
14003 73.37
14011 73.37
15003 77.25
15011 77.25
16003 81.14


The first column is always a number,My purpose is to get the second column only, like:



20.00
20.00
23.75
23.75
27.52
27.52
31.30
31.30
.
.


I intended to use



# gawk -f nset_output.awk electric_thermal.dat
BEGIN{
}
{
if($12~/NSET_OUTPUT/ ){
for(i=1;i <= 5; i++){
getline
}
x=$2

print x >"nset_output.dat"

}

}


to accomplish this.but,the output is messed up: (only one value 20.00)
20.00



So,How do I get the second column's value? (in my case I have 405 rows corresponding 405 values with 1 column)










share|improve this question















My command's output is something like:



                                   N O D E   O U T P U T

THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET NSET_OUTPUT

NODE FOOT- NT11
NOTE

3 20.00
11 20.00
1003 23.75
1011 23.75
2003 27.52
2011 27.52
3003 31.30
3011 31.30
4003 35.08
4011 35.08
5003 38.87
5011 38.87
6003 42.67
6011 42.67
7003 46.48
7011 46.48
8003 50.29
8011 50.29
9003 54.12
9011 54.12
10003 57.95
10011 57.95
11003 61.79
11011 61.79
12003 65.64
12011 65.64
13003 69.50
13011 69.50
14003 73.37
14011 73.37
15003 77.25
15011 77.25
16003 81.14


The first column is always a number,My purpose is to get the second column only, like:



20.00
20.00
23.75
23.75
27.52
27.52
31.30
31.30
.
.


I intended to use



# gawk -f nset_output.awk electric_thermal.dat
BEGIN{
}
{
if($12~/NSET_OUTPUT/ ){
for(i=1;i <= 5; i++){
getline
}
x=$2

print x >"nset_output.dat"

}

}


to accomplish this.but,the output is messed up: (only one value 20.00)
20.00



So,How do I get the second column's value? (in my case I have 405 rows corresponding 405 values with 1 column)







awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 3 '16 at 13:52









sjsam

1,1551919




1,1551919










asked Aug 3 '16 at 13:09









Ngô Tiến Hoàng

1112




1112





bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • If the header is fixed-length, you could remove it with just tail, and then awk for the other column. I'd suggest taking some care in indenting code, the snippet in the question is quite hard to interpret since the indentation and the braces do not match.
    – ilkkachu
    Aug 3 '16 at 14:24


















  • If the header is fixed-length, you could remove it with just tail, and then awk for the other column. I'd suggest taking some care in indenting code, the snippet in the question is quite hard to interpret since the indentation and the braces do not match.
    – ilkkachu
    Aug 3 '16 at 14:24
















If the header is fixed-length, you could remove it with just tail, and then awk for the other column. I'd suggest taking some care in indenting code, the snippet in the question is quite hard to interpret since the indentation and the braces do not match.
– ilkkachu
Aug 3 '16 at 14:24




If the header is fixed-length, you could remove it with just tail, and then awk for the other column. I'd suggest taking some care in indenting code, the snippet in the question is quite hard to interpret since the indentation and the braces do not match.
– ilkkachu
Aug 3 '16 at 14:24










6 Answers
6






active

oldest

votes

















up vote
0
down vote













We can test to see if the first field starts with a number and just print the second



awk '$1 ~ /^[0-9][0-9]*$/ { print $2}' electric_thermal.dat > nset_output.dat


This matches your source file and returns



20.00
20.00
23.75
23.75
27.52
27.52
31.30
31.30
....





share|improve this answer





















  • Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
    – sjsam
    Aug 3 '16 at 13:36












  • Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
    – Stephen Harris
    Aug 3 '16 at 13:48










  • Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
    – sjsam
    Aug 3 '16 at 14:05










  • Old old systems :-)
    – Stephen Harris
    Aug 3 '16 at 14:10


















up vote
0
down vote













awk is your friend:



awk '$1 ~ /^[[:digit:]]+$/{print $2}' electric_thermal.dat >outfile


should do it






share|improve this answer






























    up vote
    0
    down vote













    Assuming it's enough to check for a digit in the first column:



    awk '$1 ~ /[0-9]/ { print $2 }' data.in >data.out


    To ensure that this only gets applied to lines after the NSET_OUTPUT line, you could do something like the following:



    sed '1,/NSET_OUTPUT/d' data.in | awk '$1 ~ /[0-9]/ { print $2 }' >data.out


    This will delete lines before NSET_OUTPUT and send the rest to the awk script.





    Your script will only output one number since it, for every line of input, will look for NSET_OUTPUT, and if found, skip five lines before fetching the number from the second column.



    The following is a fixed version of your script:



    BEGIN { print_values = 0 }

    $12 ~ /NSET_OUTPUT/ {
    for (i = 1; i <= 5; i++) {
    getline;
    }

    print_values = 1;
    }

    print_values == 1 {
    x = $2;
    print x >"nset_output.dat"
    }





    share|improve this answer























    • Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
      – sjsam
      Aug 3 '16 at 13:35










    • @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
      – Kusalananda
      Aug 3 '16 at 13:44


















    up vote
    0
    down vote













    Command



     awk '$1 ~ /^[0-9]*$/{print $2}' file name


    output
    20.00
    20.00
    23.75
    23.75
    27.52
    27.52
    31.30
    31.30
    35.08
    35.08
    38.87
    38.87
    42.67
    42.67
    46.48
    46.48
    50.29
    50.29
    54.12
    54.12
    57.95
    57.95
    61.79
    61.79
    65.64
    65.64
    69.50
    69.50
    73.37
    73.37
    77.25
    77.25
    81.14





    share|improve this answer




























      up vote
      -1
      down vote













      If the above 7 lines are persistent after executing the command every time, use:



      yourcommand | sed 1,7d | awk '{print $2}'


      sed 1,7d will simply hide the first 7 lines, which you don't require. awk will sort out the exact content you are actually looking for...



      cat yourcommand_out | sed 1,7d | awk '{print $2}'
      20.00
      20.00
      23.75
      23.75
      27.52
      27.52
      31.30
      31.30
      35.08
      35.08
      38.87
      38.87
      42.67
      42.67
      46.48
      46.48
      50.29
      50.29
      54.12
      54.12
      57.95
      57.95
      61.79
      61.79
      65.64
      65.64
      69.50
      69.50
      73.37
      73.37
      77.25
      77.25
      81.14





      share|improve this answer



















      • 1




        Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
        – sjsam
        Aug 3 '16 at 14:33




















      up vote
      -2
      down vote













      Try this:



      awk '/^[ ]*[[:digit:]]/ {print $2}' inputFile





      share|improve this answer



















      • 1




        Please learn to use code blocks.
        – HalosGhost
        Aug 3 '16 at 17:16











      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: 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
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f300038%2fhow-to-get-the-second-column-from-command-output%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      We can test to see if the first field starts with a number and just print the second



      awk '$1 ~ /^[0-9][0-9]*$/ { print $2}' electric_thermal.dat > nset_output.dat


      This matches your source file and returns



      20.00
      20.00
      23.75
      23.75
      27.52
      27.52
      31.30
      31.30
      ....





      share|improve this answer





















      • Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
        – sjsam
        Aug 3 '16 at 13:36












      • Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
        – Stephen Harris
        Aug 3 '16 at 13:48










      • Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
        – sjsam
        Aug 3 '16 at 14:05










      • Old old systems :-)
        – Stephen Harris
        Aug 3 '16 at 14:10















      up vote
      0
      down vote













      We can test to see if the first field starts with a number and just print the second



      awk '$1 ~ /^[0-9][0-9]*$/ { print $2}' electric_thermal.dat > nset_output.dat


      This matches your source file and returns



      20.00
      20.00
      23.75
      23.75
      27.52
      27.52
      31.30
      31.30
      ....





      share|improve this answer





















      • Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
        – sjsam
        Aug 3 '16 at 13:36












      • Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
        – Stephen Harris
        Aug 3 '16 at 13:48










      • Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
        – sjsam
        Aug 3 '16 at 14:05










      • Old old systems :-)
        – Stephen Harris
        Aug 3 '16 at 14:10













      up vote
      0
      down vote










      up vote
      0
      down vote









      We can test to see if the first field starts with a number and just print the second



      awk '$1 ~ /^[0-9][0-9]*$/ { print $2}' electric_thermal.dat > nset_output.dat


      This matches your source file and returns



      20.00
      20.00
      23.75
      23.75
      27.52
      27.52
      31.30
      31.30
      ....





      share|improve this answer












      We can test to see if the first field starts with a number and just print the second



      awk '$1 ~ /^[0-9][0-9]*$/ { print $2}' electric_thermal.dat > nset_output.dat


      This matches your source file and returns



      20.00
      20.00
      23.75
      23.75
      27.52
      27.52
      31.30
      31.30
      ....






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 3 '16 at 13:23









      Stephen Harris

      24.1k24477




      24.1k24477












      • Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
        – sjsam
        Aug 3 '16 at 13:36












      • Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
        – Stephen Harris
        Aug 3 '16 at 13:48










      • Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
        – sjsam
        Aug 3 '16 at 14:05










      • Old old systems :-)
        – Stephen Harris
        Aug 3 '16 at 14:10


















      • Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
        – sjsam
        Aug 3 '16 at 13:36












      • Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
        – Stephen Harris
        Aug 3 '16 at 13:48










      • Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
        – sjsam
        Aug 3 '16 at 14:05










      • Old old systems :-)
        – Stephen Harris
        Aug 3 '16 at 14:10
















      Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
      – sjsam
      Aug 3 '16 at 13:36






      Why not [0-9]+ coz first column is always a number ? Also clearly the input comes from a command, so it should be piped
      – sjsam
      Aug 3 '16 at 13:36














      Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
      – Stephen Harris
      Aug 3 '16 at 13:48




      Not all versions of awk support the + syntax. The question said that data came from electric_thermal.dat
      – Stephen Harris
      Aug 3 '16 at 13:48












      Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
      – sjsam
      Aug 3 '16 at 14:05




      Hmm,,, I overlooked the comment in the script. Thanks. Regarding + I never had a problem using with them with gnu/non-gnu awks What version did you mean?
      – sjsam
      Aug 3 '16 at 14:05












      Old old systems :-)
      – Stephen Harris
      Aug 3 '16 at 14:10




      Old old systems :-)
      – Stephen Harris
      Aug 3 '16 at 14:10












      up vote
      0
      down vote













      awk is your friend:



      awk '$1 ~ /^[[:digit:]]+$/{print $2}' electric_thermal.dat >outfile


      should do it






      share|improve this answer



























        up vote
        0
        down vote













        awk is your friend:



        awk '$1 ~ /^[[:digit:]]+$/{print $2}' electric_thermal.dat >outfile


        should do it






        share|improve this answer

























          up vote
          0
          down vote










          up vote
          0
          down vote









          awk is your friend:



          awk '$1 ~ /^[[:digit:]]+$/{print $2}' electric_thermal.dat >outfile


          should do it






          share|improve this answer














          awk is your friend:



          awk '$1 ~ /^[[:digit:]]+$/{print $2}' electric_thermal.dat >outfile


          should do it







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 3 '16 at 14:06

























          answered Aug 3 '16 at 13:27









          sjsam

          1,1551919




          1,1551919






















              up vote
              0
              down vote













              Assuming it's enough to check for a digit in the first column:



              awk '$1 ~ /[0-9]/ { print $2 }' data.in >data.out


              To ensure that this only gets applied to lines after the NSET_OUTPUT line, you could do something like the following:



              sed '1,/NSET_OUTPUT/d' data.in | awk '$1 ~ /[0-9]/ { print $2 }' >data.out


              This will delete lines before NSET_OUTPUT and send the rest to the awk script.





              Your script will only output one number since it, for every line of input, will look for NSET_OUTPUT, and if found, skip five lines before fetching the number from the second column.



              The following is a fixed version of your script:



              BEGIN { print_values = 0 }

              $12 ~ /NSET_OUTPUT/ {
              for (i = 1; i <= 5; i++) {
              getline;
              }

              print_values = 1;
              }

              print_values == 1 {
              x = $2;
              print x >"nset_output.dat"
              }





              share|improve this answer























              • Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
                – sjsam
                Aug 3 '16 at 13:35










              • @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
                – Kusalananda
                Aug 3 '16 at 13:44















              up vote
              0
              down vote













              Assuming it's enough to check for a digit in the first column:



              awk '$1 ~ /[0-9]/ { print $2 }' data.in >data.out


              To ensure that this only gets applied to lines after the NSET_OUTPUT line, you could do something like the following:



              sed '1,/NSET_OUTPUT/d' data.in | awk '$1 ~ /[0-9]/ { print $2 }' >data.out


              This will delete lines before NSET_OUTPUT and send the rest to the awk script.





              Your script will only output one number since it, for every line of input, will look for NSET_OUTPUT, and if found, skip five lines before fetching the number from the second column.



              The following is a fixed version of your script:



              BEGIN { print_values = 0 }

              $12 ~ /NSET_OUTPUT/ {
              for (i = 1; i <= 5; i++) {
              getline;
              }

              print_values = 1;
              }

              print_values == 1 {
              x = $2;
              print x >"nset_output.dat"
              }





              share|improve this answer























              • Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
                – sjsam
                Aug 3 '16 at 13:35










              • @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
                – Kusalananda
                Aug 3 '16 at 13:44













              up vote
              0
              down vote










              up vote
              0
              down vote









              Assuming it's enough to check for a digit in the first column:



              awk '$1 ~ /[0-9]/ { print $2 }' data.in >data.out


              To ensure that this only gets applied to lines after the NSET_OUTPUT line, you could do something like the following:



              sed '1,/NSET_OUTPUT/d' data.in | awk '$1 ~ /[0-9]/ { print $2 }' >data.out


              This will delete lines before NSET_OUTPUT and send the rest to the awk script.





              Your script will only output one number since it, for every line of input, will look for NSET_OUTPUT, and if found, skip five lines before fetching the number from the second column.



              The following is a fixed version of your script:



              BEGIN { print_values = 0 }

              $12 ~ /NSET_OUTPUT/ {
              for (i = 1; i <= 5; i++) {
              getline;
              }

              print_values = 1;
              }

              print_values == 1 {
              x = $2;
              print x >"nset_output.dat"
              }





              share|improve this answer














              Assuming it's enough to check for a digit in the first column:



              awk '$1 ~ /[0-9]/ { print $2 }' data.in >data.out


              To ensure that this only gets applied to lines after the NSET_OUTPUT line, you could do something like the following:



              sed '1,/NSET_OUTPUT/d' data.in | awk '$1 ~ /[0-9]/ { print $2 }' >data.out


              This will delete lines before NSET_OUTPUT and send the rest to the awk script.





              Your script will only output one number since it, for every line of input, will look for NSET_OUTPUT, and if found, skip five lines before fetching the number from the second column.



              The following is a fixed version of your script:



              BEGIN { print_values = 0 }

              $12 ~ /NSET_OUTPUT/ {
              for (i = 1; i <= 5; i++) {
              getline;
              }

              print_values = 1;
              }

              print_values == 1 {
              x = $2;
              print x >"nset_output.dat"
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 7 at 8:42

























              answered Aug 3 '16 at 13:26









              Kusalananda

              120k16225367




              120k16225367












              • Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
                – sjsam
                Aug 3 '16 at 13:35










              • @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
                – Kusalananda
                Aug 3 '16 at 13:44


















              • Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
                – sjsam
                Aug 3 '16 at 13:35










              • @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
                – Kusalananda
                Aug 3 '16 at 13:44
















              Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
              – sjsam
              Aug 3 '16 at 13:35




              Keeping in mind that the command output has a header(see the question revision) which can contain stuff like 3G your regex need to be stricter to filter such values
              – sjsam
              Aug 3 '16 at 13:35












              @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
              – Kusalananda
              Aug 3 '16 at 13:44




              @sjsam Not quite sure I see that myself (looking through the revisions), but I've updated the answer nonetheless (in a way that makes it different from yours and Stephen's).
              – Kusalananda
              Aug 3 '16 at 13:44










              up vote
              0
              down vote













              Command



               awk '$1 ~ /^[0-9]*$/{print $2}' file name


              output
              20.00
              20.00
              23.75
              23.75
              27.52
              27.52
              31.30
              31.30
              35.08
              35.08
              38.87
              38.87
              42.67
              42.67
              46.48
              46.48
              50.29
              50.29
              54.12
              54.12
              57.95
              57.95
              61.79
              61.79
              65.64
              65.64
              69.50
              69.50
              73.37
              73.37
              77.25
              77.25
              81.14





              share|improve this answer

























                up vote
                0
                down vote













                Command



                 awk '$1 ~ /^[0-9]*$/{print $2}' file name


                output
                20.00
                20.00
                23.75
                23.75
                27.52
                27.52
                31.30
                31.30
                35.08
                35.08
                38.87
                38.87
                42.67
                42.67
                46.48
                46.48
                50.29
                50.29
                54.12
                54.12
                57.95
                57.95
                61.79
                61.79
                65.64
                65.64
                69.50
                69.50
                73.37
                73.37
                77.25
                77.25
                81.14





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Command



                   awk '$1 ~ /^[0-9]*$/{print $2}' file name


                  output
                  20.00
                  20.00
                  23.75
                  23.75
                  27.52
                  27.52
                  31.30
                  31.30
                  35.08
                  35.08
                  38.87
                  38.87
                  42.67
                  42.67
                  46.48
                  46.48
                  50.29
                  50.29
                  54.12
                  54.12
                  57.95
                  57.95
                  61.79
                  61.79
                  65.64
                  65.64
                  69.50
                  69.50
                  73.37
                  73.37
                  77.25
                  77.25
                  81.14





                  share|improve this answer












                  Command



                   awk '$1 ~ /^[0-9]*$/{print $2}' file name


                  output
                  20.00
                  20.00
                  23.75
                  23.75
                  27.52
                  27.52
                  31.30
                  31.30
                  35.08
                  35.08
                  38.87
                  38.87
                  42.67
                  42.67
                  46.48
                  46.48
                  50.29
                  50.29
                  54.12
                  54.12
                  57.95
                  57.95
                  61.79
                  61.79
                  65.64
                  65.64
                  69.50
                  69.50
                  73.37
                  73.37
                  77.25
                  77.25
                  81.14






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 7 at 2:06









                  Praveen Kumar BS

                  1,166138




                  1,166138






















                      up vote
                      -1
                      down vote













                      If the above 7 lines are persistent after executing the command every time, use:



                      yourcommand | sed 1,7d | awk '{print $2}'


                      sed 1,7d will simply hide the first 7 lines, which you don't require. awk will sort out the exact content you are actually looking for...



                      cat yourcommand_out | sed 1,7d | awk '{print $2}'
                      20.00
                      20.00
                      23.75
                      23.75
                      27.52
                      27.52
                      31.30
                      31.30
                      35.08
                      35.08
                      38.87
                      38.87
                      42.67
                      42.67
                      46.48
                      46.48
                      50.29
                      50.29
                      54.12
                      54.12
                      57.95
                      57.95
                      61.79
                      61.79
                      65.64
                      65.64
                      69.50
                      69.50
                      73.37
                      73.37
                      77.25
                      77.25
                      81.14





                      share|improve this answer



















                      • 1




                        Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
                        – sjsam
                        Aug 3 '16 at 14:33

















                      up vote
                      -1
                      down vote













                      If the above 7 lines are persistent after executing the command every time, use:



                      yourcommand | sed 1,7d | awk '{print $2}'


                      sed 1,7d will simply hide the first 7 lines, which you don't require. awk will sort out the exact content you are actually looking for...



                      cat yourcommand_out | sed 1,7d | awk '{print $2}'
                      20.00
                      20.00
                      23.75
                      23.75
                      27.52
                      27.52
                      31.30
                      31.30
                      35.08
                      35.08
                      38.87
                      38.87
                      42.67
                      42.67
                      46.48
                      46.48
                      50.29
                      50.29
                      54.12
                      54.12
                      57.95
                      57.95
                      61.79
                      61.79
                      65.64
                      65.64
                      69.50
                      69.50
                      73.37
                      73.37
                      77.25
                      77.25
                      81.14





                      share|improve this answer



















                      • 1




                        Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
                        – sjsam
                        Aug 3 '16 at 14:33















                      up vote
                      -1
                      down vote










                      up vote
                      -1
                      down vote









                      If the above 7 lines are persistent after executing the command every time, use:



                      yourcommand | sed 1,7d | awk '{print $2}'


                      sed 1,7d will simply hide the first 7 lines, which you don't require. awk will sort out the exact content you are actually looking for...



                      cat yourcommand_out | sed 1,7d | awk '{print $2}'
                      20.00
                      20.00
                      23.75
                      23.75
                      27.52
                      27.52
                      31.30
                      31.30
                      35.08
                      35.08
                      38.87
                      38.87
                      42.67
                      42.67
                      46.48
                      46.48
                      50.29
                      50.29
                      54.12
                      54.12
                      57.95
                      57.95
                      61.79
                      61.79
                      65.64
                      65.64
                      69.50
                      69.50
                      73.37
                      73.37
                      77.25
                      77.25
                      81.14





                      share|improve this answer














                      If the above 7 lines are persistent after executing the command every time, use:



                      yourcommand | sed 1,7d | awk '{print $2}'


                      sed 1,7d will simply hide the first 7 lines, which you don't require. awk will sort out the exact content you are actually looking for...



                      cat yourcommand_out | sed 1,7d | awk '{print $2}'
                      20.00
                      20.00
                      23.75
                      23.75
                      27.52
                      27.52
                      31.30
                      31.30
                      35.08
                      35.08
                      38.87
                      38.87
                      42.67
                      42.67
                      46.48
                      46.48
                      50.29
                      50.29
                      54.12
                      54.12
                      57.95
                      57.95
                      61.79
                      61.79
                      65.64
                      65.64
                      69.50
                      69.50
                      73.37
                      73.37
                      77.25
                      77.25
                      81.14






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 3 '16 at 16:37









                      Michael Mrozek

                      60.4k29187208




                      60.4k29187208










                      answered Aug 3 '16 at 14:24









                      Kunal Saha

                      576




                      576








                      • 1




                        Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
                        – sjsam
                        Aug 3 '16 at 14:33
















                      • 1




                        Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
                        – sjsam
                        Aug 3 '16 at 14:33










                      1




                      1




                      Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
                      – sjsam
                      Aug 3 '16 at 14:33






                      Downvote: Useless [ use of cat ], and the solution doesn't satisfy the requirements. Also please format the code.
                      – sjsam
                      Aug 3 '16 at 14:33












                      up vote
                      -2
                      down vote













                      Try this:



                      awk '/^[ ]*[[:digit:]]/ {print $2}' inputFile





                      share|improve this answer



















                      • 1




                        Please learn to use code blocks.
                        – HalosGhost
                        Aug 3 '16 at 17:16















                      up vote
                      -2
                      down vote













                      Try this:



                      awk '/^[ ]*[[:digit:]]/ {print $2}' inputFile





                      share|improve this answer



















                      • 1




                        Please learn to use code blocks.
                        – HalosGhost
                        Aug 3 '16 at 17:16













                      up vote
                      -2
                      down vote










                      up vote
                      -2
                      down vote









                      Try this:



                      awk '/^[ ]*[[:digit:]]/ {print $2}' inputFile





                      share|improve this answer














                      Try this:



                      awk '/^[ ]*[[:digit:]]/ {print $2}' inputFile






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 3 '16 at 17:16









                      HalosGhost

                      3,69592235




                      3,69592235










                      answered Aug 3 '16 at 16:40









                      KB73

                      13




                      13








                      • 1




                        Please learn to use code blocks.
                        – HalosGhost
                        Aug 3 '16 at 17:16














                      • 1




                        Please learn to use code blocks.
                        – HalosGhost
                        Aug 3 '16 at 17:16








                      1




                      1




                      Please learn to use code blocks.
                      – HalosGhost
                      Aug 3 '16 at 17:16




                      Please learn to use code blocks.
                      – HalosGhost
                      Aug 3 '16 at 17:16


















                      draft saved

                      draft discarded




















































                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f300038%2fhow-to-get-the-second-column-from-command-output%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

                      サソリ

                      広島県道265号伴広島線

                      Accessing regular linux commands in Huawei's Dopra Linux