file sizing

I need tro perform several unix command in AIX to obtain information on files,
so how would you do the following:

-  Count the number of rows in a file?
-  Get the length of the largest row in the file
-  Then multiply these two to get an exstimated file size

Thanks
mmatharuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
Hi mmatharu,

you can get the exact size by using stat or ls -l command

stat <filename>
will show you the exact filesize.

Cheers!
Sunnycoder
0
sunnycoderCommented:
Hi mmatharu,

If you want stat to produce only the filesize
stat -t CallingFeatures.h | awk ' { print $2}

Alternatively you can use
du <Filename>

-H option would show it in human readable format (kB, MB etc instead of just numbers)

Cheers!
Sunnycoder
0
XoFCommented:
print number of lines: wc -l
print length of longest line: wc -L

calculate est. file size:

wc -l -L <filename> | awk '{print "Num. of lines:\t"$1"\nLongest line:\t"$2"\nEst. Filesize:\t"$1*$2"\n"}'

HTH,
-XoF-
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

XoFCommented:
improved to also print real filesize:

wc -l -c -L <filename> | awk '{print "Num. of lines:\t"$1"\nLongest line:\t"$3"\nEst. Filesize:\t"$1*$3"\nReal Filesize:\t"$2"\n"}'

Regards,

-XoF-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmatharuAuthor Commented:
i am trying this

print length of longest line: wc -L

it is returning wc Not a recognized flag: L

0
sunnycoderCommented:
Is there any particular reason why you wish to take the long winded way when there is a more accurate and simple method available?
0
mmatharuAuthor Commented:
also I am using AIX
0
ahoffmannCommented:
> -  Count the number of rows in a file?
what is a row?
If you mean that a row is anything left of \r and/or \n then use
wc file

> -  Get the length of the largest row in the file
assuming rows to be terminated by \r and/or \n
awk '{l=length()}END{print l}' file

> -  Then multiply these two to get an exstimated file size
why would you do that if ls -l gives an 100% exact size of the file?
0
XoFCommented:
> why would you do that if ls -l gives an 100% exact size of the file?

I'd guess homework...;)

> awk '{l=length()}END{print l}' file

Hmm, isn't "l" overwritten with each iteration (each line)? I'd have assumed something like
awk '{l=length();if(max < l){max=l}}END{print max}' file

Regards,

-XoF-
0
sunnycoderCommented:
>I'd guess homework...;)

Then we shouldn't be giving away a coded solution
0
XoFCommented:
So the complete solution would look like that:

awk '{l=length();if(max < l){max=l};i++}END{print "Num. of lines:\t"i"\nLongest line:\t"l"\nEst. Filesize:\t"i*l"\n"}' file

regards,
-XoF-
0
XoFCommented:
> Then we shouldn't be giving away a coded solution

well, that's such an easy one. Hardly possible to just give hints without providing a working solution. Nevertheless, you're correct. A simple "man wc" or a link to an awk tutorial would have been the better approach. But that hadn't made me thinking about that stuff...

regards,

-XoF-
0
ahoffmannCommented:
oops, my awk was too lazy, but it works if the last line is the longest :-))
Thanks for correcting XoF.

>I'd guess homework...;)
agreed, I guess that such simple thinks won't be asked at any school, anyway the general answer then is
man ls
man wc
man awk
0
XoFCommented:
> ... but it works if the last line is the longest :-))

YMMD! ROFL.  :-))

0
mmatharuAuthor Commented:
Firstly,

Its not homework, I'm new to unix and aix and need to get an estimation on filesizes in order to calulate disk space.

Thank you for you help.
0
sunnycoderCommented:
>need to get an estimation on filesizes in order to calulate disk space.

du -H
df -H
0
mmatharuAuthor Commented:
-H it is not a recogised command is AIX
0
sunnycoderCommented:
man du
man df
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.