How to find how many values in a column are not present

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











up vote
1
down vote

favorite












I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."



For example



car.txt



Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014


So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).



The problem I'm having is the period seems to give errors when I use awk command.







share|improve this question


















  • 1




    awk '$3 ~ /./ count++ ENDprint count' file
    – jasonwryan
    Nov 19 '17 at 22:02










  • @jasonwryan that should probably be $3 == "." (else it will count decimal mpgs like 66.3 as well)
    – steeldriver
    Nov 19 '17 at 22:09










  • @steeldriver good point.
    – jasonwryan
    Nov 19 '17 at 22:10










  • @jasonwryan so u mean awk '$3 =="." ' file?
    – Maurice
    Nov 19 '17 at 22:13










  • Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Apr 28 at 11:50














up vote
1
down vote

favorite












I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."



For example



car.txt



Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014


So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).



The problem I'm having is the period seems to give errors when I use awk command.







share|improve this question


















  • 1




    awk '$3 ~ /./ count++ ENDprint count' file
    – jasonwryan
    Nov 19 '17 at 22:02










  • @jasonwryan that should probably be $3 == "." (else it will count decimal mpgs like 66.3 as well)
    – steeldriver
    Nov 19 '17 at 22:09










  • @steeldriver good point.
    – jasonwryan
    Nov 19 '17 at 22:10










  • @jasonwryan so u mean awk '$3 =="." ' file?
    – Maurice
    Nov 19 '17 at 22:13










  • Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Apr 28 at 11:50












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."



For example



car.txt



Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014


So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).



The problem I'm having is the period seems to give errors when I use awk command.







share|improve this question














I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "."



For example



car.txt



Car Colour mpg Year
vw_golf blue 56 2006
vw_polo red 66 2010
honda_civic white . 2007
ford_ka red . 2014


So the ones I'm interested in are the honda civic and ford ka as they don't have a number present for the mpg column and I want to find out how many values in the mpg column which doesn't have a value (in this case is 2).



The problem I'm having is the period seems to give errors when I use awk command.









share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '17 at 22:41









Jeff Schaller

32.1k849109




32.1k849109










asked Nov 19 '17 at 21:59









Maurice

132




132







  • 1




    awk '$3 ~ /./ count++ ENDprint count' file
    – jasonwryan
    Nov 19 '17 at 22:02










  • @jasonwryan that should probably be $3 == "." (else it will count decimal mpgs like 66.3 as well)
    – steeldriver
    Nov 19 '17 at 22:09










  • @steeldriver good point.
    – jasonwryan
    Nov 19 '17 at 22:10










  • @jasonwryan so u mean awk '$3 =="." ' file?
    – Maurice
    Nov 19 '17 at 22:13










  • Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Apr 28 at 11:50












  • 1




    awk '$3 ~ /./ count++ ENDprint count' file
    – jasonwryan
    Nov 19 '17 at 22:02










  • @jasonwryan that should probably be $3 == "." (else it will count decimal mpgs like 66.3 as well)
    – steeldriver
    Nov 19 '17 at 22:09










  • @steeldriver good point.
    – jasonwryan
    Nov 19 '17 at 22:10










  • @jasonwryan so u mean awk '$3 =="." ' file?
    – Maurice
    Nov 19 '17 at 22:13










  • Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Apr 28 at 11:50







1




1




awk '$3 ~ /./ count++ ENDprint count' file
– jasonwryan
Nov 19 '17 at 22:02




awk '$3 ~ /./ count++ ENDprint count' file
– jasonwryan
Nov 19 '17 at 22:02












@jasonwryan that should probably be $3 == "." (else it will count decimal mpgs like 66.3 as well)
– steeldriver
Nov 19 '17 at 22:09




@jasonwryan that should probably be $3 == "." (else it will count decimal mpgs like 66.3 as well)
– steeldriver
Nov 19 '17 at 22:09












@steeldriver good point.
– jasonwryan
Nov 19 '17 at 22:10




@steeldriver good point.
– jasonwryan
Nov 19 '17 at 22:10












@jasonwryan so u mean awk '$3 =="." ' file?
– Maurice
Nov 19 '17 at 22:13




@jasonwryan so u mean awk '$3 =="." ' file?
– Maurice
Nov 19 '17 at 22:13












Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Apr 28 at 11:50




Maurice, if any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Apr 28 at 11:50










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Short grep approach:



grep -Ec '^S+s+S+s+.s+' file
2




  • -E - allow extended regular expressions


  • -c - print a count of matching lines


  • S+ - match non-whitespace character(s), it is a synonym for [^[:space:]]


  • s+ - match whitespace character(s), it is a synonym for [[:space:]]





share|improve this answer



























    up vote
    0
    down vote













    Another grep method, if your file is strictly formatted to have the mpg start at column 28:



    $ grep '............................' input
    honda_civic white . 2007
    ford_ka red . 2014

    $ grep -c '............................' input
    2


    That's 28 periods (for "any" character) followed by an escaped period ("a period").



    Or with awk, as mentioned in the comments:



    $ awk '$3 == "."' input
    honda_civic white . 2007
    ford_ka red . 2014

    $ awk '$3 == "."' input | wc -l
    2





    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%2f405667%2fhow-to-find-how-many-values-in-a-column-are-not-present%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













      Short grep approach:



      grep -Ec '^S+s+S+s+.s+' file
      2




      • -E - allow extended regular expressions


      • -c - print a count of matching lines


      • S+ - match non-whitespace character(s), it is a synonym for [^[:space:]]


      • s+ - match whitespace character(s), it is a synonym for [[:space:]]





      share|improve this answer
























        up vote
        0
        down vote













        Short grep approach:



        grep -Ec '^S+s+S+s+.s+' file
        2




        • -E - allow extended regular expressions


        • -c - print a count of matching lines


        • S+ - match non-whitespace character(s), it is a synonym for [^[:space:]]


        • s+ - match whitespace character(s), it is a synonym for [[:space:]]





        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          Short grep approach:



          grep -Ec '^S+s+S+s+.s+' file
          2




          • -E - allow extended regular expressions


          • -c - print a count of matching lines


          • S+ - match non-whitespace character(s), it is a synonym for [^[:space:]]


          • s+ - match whitespace character(s), it is a synonym for [[:space:]]





          share|improve this answer












          Short grep approach:



          grep -Ec '^S+s+S+s+.s+' file
          2




          • -E - allow extended regular expressions


          • -c - print a count of matching lines


          • S+ - match non-whitespace character(s), it is a synonym for [^[:space:]]


          • s+ - match whitespace character(s), it is a synonym for [[:space:]]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '17 at 22:29









          RomanPerekhrest

          22.4k12145




          22.4k12145






















              up vote
              0
              down vote













              Another grep method, if your file is strictly formatted to have the mpg start at column 28:



              $ grep '............................' input
              honda_civic white . 2007
              ford_ka red . 2014

              $ grep -c '............................' input
              2


              That's 28 periods (for "any" character) followed by an escaped period ("a period").



              Or with awk, as mentioned in the comments:



              $ awk '$3 == "."' input
              honda_civic white . 2007
              ford_ka red . 2014

              $ awk '$3 == "."' input | wc -l
              2





              share|improve this answer
























                up vote
                0
                down vote













                Another grep method, if your file is strictly formatted to have the mpg start at column 28:



                $ grep '............................' input
                honda_civic white . 2007
                ford_ka red . 2014

                $ grep -c '............................' input
                2


                That's 28 periods (for "any" character) followed by an escaped period ("a period").



                Or with awk, as mentioned in the comments:



                $ awk '$3 == "."' input
                honda_civic white . 2007
                ford_ka red . 2014

                $ awk '$3 == "."' input | wc -l
                2





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Another grep method, if your file is strictly formatted to have the mpg start at column 28:



                  $ grep '............................' input
                  honda_civic white . 2007
                  ford_ka red . 2014

                  $ grep -c '............................' input
                  2


                  That's 28 periods (for "any" character) followed by an escaped period ("a period").



                  Or with awk, as mentioned in the comments:



                  $ awk '$3 == "."' input
                  honda_civic white . 2007
                  ford_ka red . 2014

                  $ awk '$3 == "."' input | wc -l
                  2





                  share|improve this answer












                  Another grep method, if your file is strictly formatted to have the mpg start at column 28:



                  $ grep '............................' input
                  honda_civic white . 2007
                  ford_ka red . 2014

                  $ grep -c '............................' input
                  2


                  That's 28 periods (for "any" character) followed by an escaped period ("a period").



                  Or with awk, as mentioned in the comments:



                  $ awk '$3 == "."' input
                  honda_civic white . 2007
                  ford_ka red . 2014

                  $ awk '$3 == "."' input | wc -l
                  2






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 13 at 16:32









                  Jeff Schaller

                  32.1k849109




                  32.1k849109



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405667%2fhow-to-find-how-many-values-in-a-column-are-not-present%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?