Why does wc -l tell me that this non-empty file has 0 lines? The 2019 Stack Overflow Developer Survey Results Are InBash test wc with '-ge' - division by 0 errorGet last set of non-empty linesHow can I delete lines that has an empty first column?What does this “matching lines means”?Why the inconsistency with using cat vs. echo piped to this sed command?How many lines of code are in this file?Calling latex from vim stopped workingprint only rows that has latest non empty cell that starts with the word “Failed” on a CSV file in LinuxHow to exclude lines that has given columns?How to remove the lines that have empty fields?Trying to print full line from a huge file that has (connector for lines)

What did it mean to "align" a radio?

Can you compress metal and what would be the consequences?

Interpreting the 2019 New York Reproductive Health Act?

How to check whether the reindex working or not in Magento?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Reference request: Oldest number theory books with (unsolved) exercises?

What does ひと匙 mean in this manga and has it been used colloquially?

Return to UK after having been refused entry years ago

Is a "Democratic" Oligarchy-Style System Possible?

Falsification in Math vs Science

Have you ever entered Singapore using a different passport or name?

Feature engineering suggestion required

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Am I thawing this London Broil safely?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

How are circuits which use complex ICs normally simulated?

Looking for Correct Greek Translation for Heraclitus

Does the shape of a die affect the probability of a number being rolled?

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

Does coating your armor in silver add any effects?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

When should I buy a clipper card after flying to OAK?



Why does wc -l tell me that this non-empty file has 0 lines?



The 2019 Stack Overflow Developer Survey Results Are InBash test wc with '-ge' - division by 0 errorGet last set of non-empty linesHow can I delete lines that has an empty first column?What does this “matching lines means”?Why the inconsistency with using cat vs. echo piped to this sed command?How many lines of code are in this file?Calling latex from vim stopped workingprint only rows that has latest non empty cell that starts with the word “Failed” on a CSV file in LinuxHow to exclude lines that has given columns?How to remove the lines that have empty fields?Trying to print full line from a huge file that has (connector for lines)



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








4















xclip/xsel are utilities that allow you to pipe clipboard output to the shell on Ubuntu. Unfortunately, they seem to fail in combination with the wc command.



Try this. Open a new file and type:



this is a line


without hitting the enter key at the end of the line.



Now, copy this text and try the following:



$ xsel -o | wc -l
0


The output is 0, when in fact it should be 1. Save the file (call it myfile.txt).



Now try:



$ cat myfile.txt | wc -l
1


The output is 1, as expected.



Why is the output 0 in the first case?










share|improve this question






























    4















    xclip/xsel are utilities that allow you to pipe clipboard output to the shell on Ubuntu. Unfortunately, they seem to fail in combination with the wc command.



    Try this. Open a new file and type:



    this is a line


    without hitting the enter key at the end of the line.



    Now, copy this text and try the following:



    $ xsel -o | wc -l
    0


    The output is 0, when in fact it should be 1. Save the file (call it myfile.txt).



    Now try:



    $ cat myfile.txt | wc -l
    1


    The output is 1, as expected.



    Why is the output 0 in the first case?










    share|improve this question


























      4












      4








      4


      1






      xclip/xsel are utilities that allow you to pipe clipboard output to the shell on Ubuntu. Unfortunately, they seem to fail in combination with the wc command.



      Try this. Open a new file and type:



      this is a line


      without hitting the enter key at the end of the line.



      Now, copy this text and try the following:



      $ xsel -o | wc -l
      0


      The output is 0, when in fact it should be 1. Save the file (call it myfile.txt).



      Now try:



      $ cat myfile.txt | wc -l
      1


      The output is 1, as expected.



      Why is the output 0 in the first case?










      share|improve this question
















      xclip/xsel are utilities that allow you to pipe clipboard output to the shell on Ubuntu. Unfortunately, they seem to fail in combination with the wc command.



      Try this. Open a new file and type:



      this is a line


      without hitting the enter key at the end of the line.



      Now, copy this text and try the following:



      $ xsel -o | wc -l
      0


      The output is 0, when in fact it should be 1. Save the file (call it myfile.txt).



      Now try:



      $ cat myfile.txt | wc -l
      1


      The output is 1, as expected.



      Why is the output 0 in the first case?







      text-processing newlines wc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 13 '17 at 12:22









      Community

      1




      1










      asked Jul 17 '13 at 18:51









      CodeBlueCodeBlue

      51751020




      51751020




















          2 Answers
          2






          active

          oldest

          votes


















          4














          The issue you're experiencing is that wc -l counts new lines. Since you haven't in fact typed the n there is in fact zero new lines.



          excerpt from wc man page




          Print newline, word, and byte counts for each FILE, and a total line
          if more than one FILE is specified. With no FILE, or when FILE is -,
          read standard input. A word is a non-zero-length sequence of
          characters delimited by white space.




          If you switch it around so that wc counts characters (-c) you'll see that it is in fact working just fine and can count the number of characters:



          $ xsel -o | wc -c
          14


          Saving it to a file has the effect of adding a newline at the end of the file.






          share|improve this answer
































            0














            wc counts the end of line characters. The first time you just marked the text, not containing any end of line character. When you save the file, the editor appends an end of line character which is counted by wc.






            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',
              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/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%2f83408%2fwhy-does-wc-l-tell-me-that-this-non-empty-file-has-0-lines%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









              4














              The issue you're experiencing is that wc -l counts new lines. Since you haven't in fact typed the n there is in fact zero new lines.



              excerpt from wc man page




              Print newline, word, and byte counts for each FILE, and a total line
              if more than one FILE is specified. With no FILE, or when FILE is -,
              read standard input. A word is a non-zero-length sequence of
              characters delimited by white space.




              If you switch it around so that wc counts characters (-c) you'll see that it is in fact working just fine and can count the number of characters:



              $ xsel -o | wc -c
              14


              Saving it to a file has the effect of adding a newline at the end of the file.






              share|improve this answer





























                4














                The issue you're experiencing is that wc -l counts new lines. Since you haven't in fact typed the n there is in fact zero new lines.



                excerpt from wc man page




                Print newline, word, and byte counts for each FILE, and a total line
                if more than one FILE is specified. With no FILE, or when FILE is -,
                read standard input. A word is a non-zero-length sequence of
                characters delimited by white space.




                If you switch it around so that wc counts characters (-c) you'll see that it is in fact working just fine and can count the number of characters:



                $ xsel -o | wc -c
                14


                Saving it to a file has the effect of adding a newline at the end of the file.






                share|improve this answer



























                  4












                  4








                  4







                  The issue you're experiencing is that wc -l counts new lines. Since you haven't in fact typed the n there is in fact zero new lines.



                  excerpt from wc man page




                  Print newline, word, and byte counts for each FILE, and a total line
                  if more than one FILE is specified. With no FILE, or when FILE is -,
                  read standard input. A word is a non-zero-length sequence of
                  characters delimited by white space.




                  If you switch it around so that wc counts characters (-c) you'll see that it is in fact working just fine and can count the number of characters:



                  $ xsel -o | wc -c
                  14


                  Saving it to a file has the effect of adding a newline at the end of the file.






                  share|improve this answer















                  The issue you're experiencing is that wc -l counts new lines. Since you haven't in fact typed the n there is in fact zero new lines.



                  excerpt from wc man page




                  Print newline, word, and byte counts for each FILE, and a total line
                  if more than one FILE is specified. With no FILE, or when FILE is -,
                  read standard input. A word is a non-zero-length sequence of
                  characters delimited by white space.




                  If you switch it around so that wc counts characters (-c) you'll see that it is in fact working just fine and can count the number of characters:



                  $ xsel -o | wc -c
                  14


                  Saving it to a file has the effect of adding a newline at the end of the file.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 17 '13 at 19:20

























                  answered Jul 17 '13 at 19:14









                  slmslm

                  256k71544689




                  256k71544689























                      0














                      wc counts the end of line characters. The first time you just marked the text, not containing any end of line character. When you save the file, the editor appends an end of line character which is counted by wc.






                      share|improve this answer



























                        0














                        wc counts the end of line characters. The first time you just marked the text, not containing any end of line character. When you save the file, the editor appends an end of line character which is counted by wc.






                        share|improve this answer

























                          0












                          0








                          0







                          wc counts the end of line characters. The first time you just marked the text, not containing any end of line character. When you save the file, the editor appends an end of line character which is counted by wc.






                          share|improve this answer













                          wc counts the end of line characters. The first time you just marked the text, not containing any end of line character. When you save the file, the editor appends an end of line character which is counted by wc.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jul 17 '13 at 19:15









                          MarcoMarco

                          25.5k784120




                          25.5k784120



























                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f83408%2fwhy-does-wc-l-tell-me-that-this-non-empty-file-has-0-lines%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







                              -newlines, text-processing, wc

                              Popular posts from this blog

                              Frič See also Navigation menuinternal link

                              Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

                              fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox