bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wrong result from wc


From: Eric Blake
Subject: Re: wrong result from wc
Date: Fri, 18 Jan 2008 06:54:22 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Manu Hack on 1/18/2008 12:59 AM:
| Hi,
|
| I have a data file attached.  When I run

Please restrain from posting 5 megabyte files to every reader of this list
- - first try to narrow your problem down to something MUCH smaller.

|
| wc -l < r.dat
|
| it gives 999.

As well it should - your file only contained 999 newlines.

|
| but when I open the file with vim, it shows 1000 lines.  Also,

POSIX defines a line as text ending with a newline.  So even though there
are 1000 rows (and vim shows all 1000 rows), there are only 999 complete
lines, and the file ends in an incomplete line and is not a text file (the
POSIX definition of a text file includes the stipulation on no incomplete
line unless the file is empty).

|
| cut -d ' ' -f1 r.dat | wc -l
|
| gives 1000.

As well it should, since cut puts a newline after everything that it cuts
from the file, whether or not it is cutting from an incomplete line.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHkK+O84KuGfSFAYARAhj6AJ9qNUNjNQDn+C0ZQ/J0tyTz2Ra66ACfQbvO
ztYkRDyFpNTAxl5UghMdogk=
=VeVT
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]