Operating System - Linux
1748151 Members
3504 Online
108758 Solutions
New Discussion юеВ

How to tell how many records in a file

 
SOLVED
Go to solution
Randy Hagedorn
Regular Advisor

How to tell how many records in a file

Hi,

I would like to know how to know, how many records actually exist in a file. When using ls -al, it displays the total disc space, but not how many records.

Thanks,
Randy
4 REPLIES 4
Patrick Wallek
Honored Contributor
Solution

Re: How to tell how many records in a file

If you are talking about a regular ASCII file, you can do a 'wc -l ' to see the number of lines in a file.

There are other option to 'wc' as well. Have a look at the man page for more info.
A. Clay Stephenson
Acclaimed Contributor

Re: How to tell how many records in a file

UNIX has no concept of records. That is purely a function of the application. You can use wc to count the number of lines and if an ASCII LF is used as a record marker then you have the number of records. If the records are fixed size then the file length / record size will yield the number of records although it is not uncommon for data files to use a header area so this reduces the total number of actual data records. What you may be able to do (if you don't know the record length) is to use od or xd to recogize repeating patterns (ie Names) and the file offsets at which they occur to determine the record size. The most difficult of all are variable sizes records in which the length and offset to the next record are encoded in the current record.
If it ain't broke, I can fix that.
Prashant Zanwar_4
Respected Contributor

Re: How to tell how many records in a file

wc -c to see charcters, wc -l file to see number of lines..

Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Randy Hagedorn
Regular Advisor

Re: How to tell how many records in a file

Thanks to all for your insights on the inner workings of Unix. The files in question are fixed length records, which is were I hoped the wc -l would work, but the results were inaccurate. I think it may be due to the make-up of the data, which contains, string, packed and binary data all in a single record.

However, I will be able to calculate the number of records by doing the wc -c dividing it by the record length to yield the number of records.

Randy