If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Pls Help with Awk Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-19-03, 22:39
rrohde rrohde is offline
Registered User
 
Join Date: Nov 2003
Location: Australia
Posts: 2
Pls Help with Awk Script

Hi all, wondering if anyone can help.

Im currently trying to write a script that takes my users connection stats
and rewrites it to individual user files.

the data is in the form of a comma delimited text file

Fields
server name$1 ,name,port no,in date,in time,out date,out time,min,bytes sent,bytes received,port speed,how off,unique id

I know how to format
How do I set the script to write a file for each new name in $2 and then add up all the times and downloads ($8, $9, $10) in those user specific files .

Thank you for your assistance
Reply With Quote
  #2 (permalink)  
Old 11-20-03, 05:29
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: Pls Help with Awk Script

Quote:
Originally posted by rrohde
Hi all, wondering if anyone can help.

Im currently trying to write a script that takes my users connection stats
and rewrites it to individual user files.

the data is in the form of a comma delimited text file

Fields
server name$1 ,name,port no,in date,in time,out date,out time,min,bytes sent,bytes received,port speed,how off,unique id

I know how to format
How do I set the script to write a file for each new name in $2 and then add up all the times and downloads ($8, $9, $10) in those user specific files .

Thank you for your assistance
I think this should do what you are asking...

awk -F"," ' {
time[$2]+=$8
bytesSent[$2]+=$9
bytesReceived[$2]+=$10
}
END {
for (fileName in time) {
print "Time="time[fileName], "Sent="bytesSent[fileName], "Received="bytesReceived[fileName] > fileName
}
}' yourFile

Damian

Last edited by Damian Ibbotson; 11-26-03 at 11:23.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On