Link to home
Start Free TrialLog in
Avatar of gram77
gram77Flag for India

asked on

How do I calculate the filesize of myfile.dat in awk?

Here is the script
cat myfile.dat | awk '{print $1 "\t\t" $2;lines++} END {print "Rows--> " lines  "Filesize:--> "}'

Data/Result:
TRX               TRXAMT
10              100
20              200
30              300
40              400
50              500
Rows-->5 Filesize-->
Avatar of gram77
gram77
Flag of India image

ASKER

I don't want to use wc -l to check for the filesize. I want to awk code.
ASKER CERTIFIED SOLUTION
Avatar of ghostdog74
ghostdog74

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gram77

ASKER

ghostdog, ozo:
can you explain how your program works.

Ghostdog: how does a+=$2 calculate file size
ozo: how does a+lines calculate file size.
Avatar of ghostdog74
ghostdog74

a+=$2  is equivalent to a=a+$2
Avatar of gram77

ASKER

ghostdog74:
That i know. Could you please tell me how your solution works?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial