Operating System - HP-UX
1834020 Members
3095 Online
110063 Solutions
New Discussion

How do you determine the record length of a file

 
SOLVED
Go to solution
wvsa
Regular Advisor

How do you determine the record length of a file

Greetings, running 11.0 how can I determine the record length of records in a file? Thankyou for your help..
3 REPLIES 3
Rita C Workman
Honored Contributor

Re: How do you determine the record length of a file

If you want to know how many lines are in a file...

cat | wc -l

See manpage wc

Regards,
/rcw

James R. Ferguson
Acclaimed Contributor
Solution

Re: How do you determine the record length of a file

Hi:

# wc

will return three numbers which are the number of lines, the number of words, and the number of characters, respectively. Assuming you have fixed size records, then you could do the following to find the "record size" (including the newline character at the end of each record:

# wc file|awk '{print $3 / $1}'

...JRF...
Rodney Hills
Honored Contributor

Re: How do you determine the record length of a file

Run-
awk '{if (length($0) > x) x=length($0)}END{print "Max rec len" x}' yourinputfile

This awk script will find the maximum record length in the file.
There be dragons...