LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-01-2011, 04:47 AM   #1
kiloman
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Rep: Reputation: 0
concatenate data from different lines


Hi everybody.

I want to concatenate info from different lines from iptables. for exmaple, in my firewall using iptables I have this information.



pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- * * 192.168.1.3 0.0.0.0/0
5 248 ACCEPT all -- * * 0.0.0.0/0 192.168.1.3

This shows how many bytes a user with ip 192.168.1.3 has down- and uploaded. I now want to print out a line that looks like this.

"IP, downloaded bytes, uploaded bytes"

But since informations are split over two lines i don't know how to combine them.

In a real world example there will of course be many more lines.

Hope someone can help.

Thanks.
 
Old 03-01-2011, 07:15 AM   #2
rizhun
Member
 
Registered: Jun 2005
Location: England
Distribution: Ubuntu, SLES, AIX
Posts: 268

Rep: Reputation: 47
Hello kiloman,

This feels like homework, so I'll just point you in the general direction

There are several ways to do this.
You could do it all in Perl, or you could do it just from a command prompt.

If you went down the command prompt route, you can join every other line using 'sed':
Code:
$ /your/iptables/command --andopts | sed '$!N;s/\n/ /'
You could then pipe this output through 'awk' and just output the fields you want:
Code:
$ /your/iptables/command --andopts | sed '$!N;s/\n/ /' | awk 'BEGIN { print "IP downloaded-bytes uploaded-bytes" } { print $1 " " $2 " " $3 }'
(the positional parameters used above ($1, $2 and $3) would need setting to whatever field you required, based on the output of the first command)

This code presumes that your iptables command only shows you the data, and there are no column names or other identifiers in the mix. I don't use iptables, so I'm not familiar with the layout.

Good luck!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Extract multiple lines of data from a text file. shawnamiller Programming 8 04-30-2010 11:46 AM
extracting lines from very large data files lothario Linux - Software 1 12-15-2009 09:22 PM
have a Variable with multiple lines of data need to have it all on one line seperated xskycamefalling Programming 11 05-12-2009 04:44 AM
Concatenate column 1 and column 2 of related lines cgcamal Programming 4 11-20-2008 10:43 AM
use file data in command lines karlis Linux - General 3 08-29-2003 07:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration