Trying to combine upload and download totals from txt file by ip address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to combine upload and download totals from txt file by ip address
# 1  
Old 09-06-2010
Trying to combine upload and download totals from txt file by ip address

I have two files, uploads.txt and downloads.txt. I would like to combine the columns of these files based on the ip address. How can I best do this?

Uploads.txt
Code:
192.168.0.147 1565369
192.168.0.13 1664855
192.168.0.6 1332868

Downloads.txt
Code:
192.168.0.147 9838820
192.168.0.18 12051718
192.168.0.6 7633159

I want something that looks like
Code:
192.168.0.147 9999999999
192.168.0.18 9999999999
192.168.0.13 9999999999
192.168.0.6 9999999999

where 999999 is the sum of the downloads and uploads.

Thank you!
# 2  
Old 09-06-2010
Try this:
Code:
awk '{a[$1]+=$2}END{for(i in a)print i, a[i]}' uploads.txt downloads.txt

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 09-06-2010
Thank you so much! It worked beautifully!

---------- Post updated at 04:34 PM ---------- Previous update was at 04:31 PM ----------

Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '{a[$1]+=$2}END{for(i in a)print i, a[i]}' uploads.txt downloads.txt


any chance that this or something like it would work from streams? IE:

Code:
iptables -nvx -L FORWARD | awk '$8 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/{print $8,$2}


Last edited by Franklin52; 09-06-2010 at 09:50 AM.. Reason: cleaned unintended? bumps
# 4  
Old 09-06-2010
Quote:
Originally Posted by zanyspydude
Thank you so much! It worked beautifully!

---------- Post updated at 04:34 PM ---------- Previous update was at 04:31 PM ----------

any chance that this or something like it would work from streams? IE:

Code:
iptables -nvx -L FORWARD | awk '$8 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/{print $8,$2}

How does the output look like and what is the desired output?
# 5  
Old 09-06-2010
alternative way Smilie
Code:
# sed 's/ .*//' Uploads.txt Downloads.txt  | sort -t"." -u -k4,7rn | sed 's/\(.*\)/\1 9999999999/'
192.168.0.147 9999999999
192.168.0.18 9999999999
192.168.0.13 9999999999
192.168.0.6 9999999999

# 6  
Old 09-06-2010
Quote:
Originally Posted by ygemici
alternative way Smilie
Code:
# sed 's/ .*//' Uploads.txt Downloads.txt  | sort -t"." -u -k4,7rn | sed 's/\(.*\)/\1 9999999999/'
192.168.0.147 9999999999
192.168.0.18 9999999999
192.168.0.13 9999999999
192.168.0.6 9999999999

Have you read the question carefully?

The last column must be the sum of the downloads and uploads.

Quote:
Originally Posted by zanyspydude
where 999999 is the sum of the downloads and uploads.
# 7  
Old 09-06-2010
Code:
iptables -nvx -L FORWARD |awk '$8 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ {a[$8]+=$2}END{for(i in a)print i, a[i]}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Retrieve/download SSH key instead of Send/Upload?

Hi, is it possible to download/retrieve a public SSH key when you are logged in to the remote machine rather than sending the key, for example with ssh-copy-id from your local machine to the remote machine? I can only ssh into one direction (from the remote machine into the local machine),... (5 Replies)
Discussion started by: gczychi
5 Replies

2. Shell Programming and Scripting

Download pdf's using wget convert to txt

wget -i genedx.txt The code above will download multiple pdf files from a site, but how can i download and convert these to .txt? I have attached the master list (genedx.txt - which contains the url and file names) as well as the two PDF's that are downloaded. I am trying to have those... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

4. Solaris

Solaris 10 - A User Can Download File but Cannot Upload

Dear all, I have made a search on the forum, but couldn't find a related topic about this issue. * I have created a user on Solaris 10 OS with below command and then set password for the user. * Now i can FTP to OS with this user (hattesti). Although i can download files under related... (0 Replies)
Discussion started by: byrusber
0 Replies

5. Shell Programming and Scripting

Shell Script for Upload/download files using cURL

hi please help me out here, i want to use curl command in shell script to test web pages, what i have is an opening page, when i click on a button on opening page, the next page comes up and then i have to upload a file n then click another button to submit and then comes the output page,... (2 Replies)
Discussion started by: Olivia
2 Replies

6. Shell Programming and Scripting

Totals in a file - incorrectly displaying

Afternoon, I have a script which creates/modifies data into a formatted csv. The trailer record should display 2 columns, the first is a static entry of "T" to identify it as a trailer record. The 2nd is a total of amounts in a column throughout the entire file. My total isn't displaying... (8 Replies)
Discussion started by: mcclunyboy
8 Replies

7. Shell Programming and Scripting

Getting upload and download speeds with the help of script?How?

How can I get the upload and download speed of my pc, provided that my interface is wlan0? I have though something like: #!/bin/sh ups=something downs=somethingelse echo " Your current up speed is $ups Your current down speed is $downs, but I have no idea how to get them?Are... (5 Replies)
Discussion started by: hakermania
5 Replies

8. Shell Programming and Scripting

[Solved] Find Specific records from file and add totals into variables

Hi Eveyone, I am working on one shell script to find the specific records from data file and add the totals into variables and print them. you can find the sample data file below for more clarification. Sample Data File: PXSTYL00__20090803USA CHCART00__20090803IND... (7 Replies)
Discussion started by: veeru
7 Replies

9. Linux

restrict file download not upload

hi everybody, How cud i stop downloading files from FTP and allow uploading files in FTP. Thanks & reg, (2 Replies)
Discussion started by: utpalsarkar
2 Replies

10. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies
Login or Register to Ask a Question