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!

Need to subtotal columns of a file

Status
Not open for further replies.

itsmythg

Technical User
Apr 4, 2001
34
US
My problem is I am an administrator not code writer, but I need to total the columns in some data I am pulling out of the system accounting files. Basicly I am cutting out those processes I am interested in and writing to a file i need to total colum 5 and 6 of the files to total processor time and characters transfered.


This is file
cpu char
trans
uname xxxxx 10:00:01 10:00:01 0.03 8 0 whoami xxxxx 10:00:01 10:00:01 0.03 9 0
uname xxxxx 10:00:01 10:00:01 0.02 6 0

this is the script works except gives me zero totals and I need it to identify what total it is totaling

cat pacct* | grep airprice >air |ls -l air| awk '{sum +=$5} END {print sum}' >da
ta
 
I'm guessing it's because you're not passing the results of grep into awk, only the result of an ls -l command. The awk script looks fine. If you don't need the air file, this should work;

grep airprice pacct* | awk '{sum+=$5} END {print sum}' > da

If that doesn't work (depending on the exact filetype of pacct* files), this should;

cat pacct* | grep airprice | awk '{sum+=$5} END {print sum}' > da

Greg.
 
problem is that it does not recognizing the column count as 5 I tried 6 & 7 thought should use charcter count which is what I had to do for a cut of this file I am not sure how represent the charecter it is.

Thanks for all your help - will take some classes for writing code as soon as I can. I would rather be the mechanic and thought if I don't learn it I won't have to use it HA HA my avoiding time is over.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top