Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count of a column total

Status
Not open for further replies.

teser

Technical User
Mar 6, 2001
194
US
How can i count the total value of a column. I want the total size of a several files that begin with b.

Example:
ls -l b*
-rw-r--r-- 1 smith agr 2501 Mar 7 10:43 bk131.sql
-rw-r--r-- 1 smith agr 2532 Mar 7 10:43 bk131a.sql

I need the total value of column 5 (2501 + 2532). Is there a command or simple script that can handle this?
 
This should do it ...

ls -l b*|awk '{s+=$5} END {print s}'

Post back if there are any problems.

Greg.
 
Greg,

Thanks for your quick response.

 
No probs ... nothing better to do today anyway! :)

Greg.
 

Teser,

it's easy with awk. Please, try this command:

ls -l b* | awk '{ sum += $5 } END { print sum }'

Bye!

KP.
 

Sorry teser and grega,

grega was faster.

Bye!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top