The wc -l gives wrong result

I got wrong result from the wc -l command. After a long :( checking a found the core of the problem, here is the simulation:

$ echo "line with end" > file
$ echo -n "line without end" >>file
$ wc -l file
       1 file

here are two lines, but missing the last "\n". Any easy solution?


For the wc line is what ends with the "\n" char. One of solutions is grep-ing the lines. The grep not looking for the ending NL.


$ grep -c . file        #count the occurrence of any character

the above will not count empty lines. If you want them, use the

$ grep -c '^' file      #count the beginnings of the lines

from man page of wc

 -l, --lines
              print the newline counts

form man page of echo

 -n     do not output the trailing newline

so you have 1 newline in your file and thus wc -l shows 1.

You can use the following awk command to count lines

 awk 'END{print NR}' file

Need Your Help

How can i call an exe from html page?

javascript html exe

I have a web app that must be run from a CDROM.

How to link js datetime picker to input tag with id &/or class of minDate in an mvc

c# javascript jquery html

I am currently trying to make a input tag display a calendar with jquery on an MVC. I am not sure if i am linking it correctly as I am new to MVC's.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.