Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WC command of mac showing one less result

Tags:

unix

I have a text file which has over 60MB size. It has got entries in 5105043 lines, but when I am doing wc -l it is giving only 5105042 results which is one less than actual. Does anyone have any idea why it is happening?

Is it a common thing when the file size is large?

like image 282
Dude Avatar asked Sep 27 '12 07:09

Dude


People also ask

What is the output of wc command?

wc stands for word count. As the name implies, it is mainly used for counting purpose. It is used to find out number of lines, word count, byte and characters count in the files specified in the file arguments. By default it displays four-columnar output.

Does wc return an integer?

sure it does, you just pass in the proper parameters that you would anyway. for example, if you do wc -c < file name , it will give you just the integer number of bytes and nothing else.

What is wc bash command?

The “wc” or the word count command in Bash is considered extremely useful as it helps in finding out various statistics of a file. This command can be used in multiple different variations.

Which option should we use to count no of lines in wc command?

-l Option. Display the number of lines in the file.


1 Answers

Last line does not contain a new line.

One trick to get the result you want would be:

sed -n '=' <yourfile> | wc -l

This tells sed just to print the line number of each line in your file which wc then counts. There are probably better solutions, but this works.

like image 79
John3136 Avatar answered Oct 20 '22 23:10

John3136