How to count empty line using grepWhat makes grep consider a file to be binary?Count lines matching pattern...

When did computers stop checking memory on boot?

UK citizen travelling to France at the end of November

How should Thaumaturgy's "three times as loud as normal" be interpreted?

What is the difference between a translation and a Galilean transformation?

Are programming languages necessary/useful for operations research practitioner?

How should we understand "unobscured by flying friends" in this context?

How to set any file manager in Linux to show the duration like the Length feature in Windows Explorer?

Is it unavoidable taking shortcuts in software development sometimes?

What is the difference between tl_to_str:V and tl_to_str:N?

A word for decorative cords on uniforms

Chandrayaan 2: Why is Vikram Lander's life limited to 14 Days?

Bit floating sequence

Owner keeps cutting corners and poaching workers for his other company

I multiply the source, you (probably) multiply the output!

How can Schrödinger's cat be both dead and alive?

Features seen on the Space Shuttle's solid booster; what does "LOADED" mean exactly?

Is a MySQL database a viable alternative to LDAP?

Why does low tire pressure decrease fuel economy?

How can faith be maintained in a world of living gods?

pgfgantt: month displayed as single letter

How do you say "to hell with everything" in French?

Are personality traits, ideals, bonds, and flaws required?

WPF MVVM ColorLister with navigation

I need to know information from an old German birth certificate



How to count empty line using grep


What makes grep consider a file to be binary?Count lines matching pattern and matching previous lineCount number of a substring repetition in a stringHow to “grep” for line length *not* in a given range?Count text occurrences per lineHow do I grep many files for many strings?Using grep to find multiple repeating characters in a wordsearching letters in one line using grep and wc






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:



123

// comment
45


As you can see, there is a line above //comment. If I want to count the times such line exist in my file, how can I grep them?










share|improve this question







New contributor



user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    0















    I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:



    123

    // comment
    45


    As you can see, there is a line above //comment. If I want to count the times such line exist in my file, how can I grep them?










    share|improve this question







    New contributor



    user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0












      0








      0








      I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:



      123

      // comment
      45


      As you can see, there is a line above //comment. If I want to count the times such line exist in my file, how can I grep them?










      share|improve this question







      New contributor



      user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:



      123

      // comment
      45


      As you can see, there is a line above //comment. If I want to count the times such line exist in my file, how can I grep them?







      text-processing files grep search






      share|improve this question







      New contributor



      user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 36 mins ago









      user12019159user12019159

      31 bronze badge




      31 bronze badge




      New contributor



      user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      user12019159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          1 Answer
          1






          active

          oldest

          votes


















          2
















          You can grep empty lines with grep '^$' file and count the lines with wc -l. Combined it's:



          grep '^$' file | wc -l


          or even shorter with grep's count option -c or --count



          grep -c '^$' file





          share|improve this answer























          • 1





            See also grep -c

            – Stephen Harris
            29 mins ago











          • Thanks @StephenHarris ! I totally forgot this option.

            – Freddy
            25 mins ago














          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',
          autoActivateHeartbeat: false,
          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/4.0/"u003ecc by-sa 4.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
          });


          }
          });







          user12019159 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded
















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539706%2fhow-to-count-empty-line-using-grep%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2
















          You can grep empty lines with grep '^$' file and count the lines with wc -l. Combined it's:



          grep '^$' file | wc -l


          or even shorter with grep's count option -c or --count



          grep -c '^$' file





          share|improve this answer























          • 1





            See also grep -c

            – Stephen Harris
            29 mins ago











          • Thanks @StephenHarris ! I totally forgot this option.

            – Freddy
            25 mins ago
















          2
















          You can grep empty lines with grep '^$' file and count the lines with wc -l. Combined it's:



          grep '^$' file | wc -l


          or even shorter with grep's count option -c or --count



          grep -c '^$' file





          share|improve this answer























          • 1





            See also grep -c

            – Stephen Harris
            29 mins ago











          • Thanks @StephenHarris ! I totally forgot this option.

            – Freddy
            25 mins ago














          2














          2










          2









          You can grep empty lines with grep '^$' file and count the lines with wc -l. Combined it's:



          grep '^$' file | wc -l


          or even shorter with grep's count option -c or --count



          grep -c '^$' file





          share|improve this answer















          You can grep empty lines with grep '^$' file and count the lines with wc -l. Combined it's:



          grep '^$' file | wc -l


          or even shorter with grep's count option -c or --count



          grep -c '^$' file






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 26 mins ago

























          answered 31 mins ago









          FreddyFreddy

          7,4931 gold badge6 silver badges25 bronze badges




          7,4931 gold badge6 silver badges25 bronze badges











          • 1





            See also grep -c

            – Stephen Harris
            29 mins ago











          • Thanks @StephenHarris ! I totally forgot this option.

            – Freddy
            25 mins ago














          • 1





            See also grep -c

            – Stephen Harris
            29 mins ago











          • Thanks @StephenHarris ! I totally forgot this option.

            – Freddy
            25 mins ago








          1




          1





          See also grep -c

          – Stephen Harris
          29 mins ago





          See also grep -c

          – Stephen Harris
          29 mins ago













          Thanks @StephenHarris ! I totally forgot this option.

          – Freddy
          25 mins ago





          Thanks @StephenHarris ! I totally forgot this option.

          – Freddy
          25 mins ago











          user12019159 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded

















          user12019159 is a new contributor. Be nice, and check out our Code of Conduct.













          user12019159 is a new contributor. Be nice, and check out our Code of Conduct.












          user12019159 is a new contributor. Be nice, and check out our Code of Conduct.
















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539706%2fhow-to-count-empty-line-using-grep%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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...