Sponsored Content
Top Forums Shell Programming and Scripting Awk to count matching IP address Post 302199555 by new_buddy on Tuesday 27th of May 2008 07:04:48 AM
Old 05-27-2008
Awk to count matching IP address

Hi all,

I am kinda new to unix and shell programming. I am stucked with the raw data to do the filtering things. Generally, the output should count unique connected destination for each source and total of flows for it. Here is the example of input file:
Code:
  Source IP               Dest IP           No. of Flows
222.233.123.136   192.168.129.197      9
221.241.57.125    192.168.129.197      22
221.241.57.125    192.168.128.210       1
221.187.240.145   192.168.129.197     6
221.128.134.247   192.168.129.197     18
221.128.134.247   192.168.129.1        20

The output should be like this format
Code:
222.233.123.136   1     9
221.241.57.125     2    23
221.187.240.145    1    6
221.128.134.247   2    38

I am using awk for this job. Really need for help. Thanks in advance
Here is the piece of my coding.
Code:
awk 'BEGIN{SUBSEP="@"}
	
	count=0
 	{ for(i=1;i < NF;i++) 
	{ if ($i==$1)
		{ 
		src=$1
		conn=$3
		count++
		}
	}
	{
	if ($1==src)
	{
	while (count>1)
	{ conn += $3 }
	}	
	}
		unique[src,conn]++
}
	
			
END{
	for (i in unique){
	n=split(i,u,SUBSEP)
	print u[1]"   " unique[i]"  "u[2]
 
}

}' tcpfile.sorted | sort -rn >> tcpfile.unique
}


Last edited by Yogesh Sawant; 05-27-2008 at 08:22 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

2. Shell Programming and Scripting

Pattern Matching Count Urgent

The input is like NO Code 030019991 22 030087819 0 030089001 22 030178901 39 030333333 22 Patterns i want to match is 0300 0301 0303. i want to count different Codes occurances for each of these pattern. for example for 0300 Code 22... (6 Replies)
Discussion started by: krabu
6 Replies

3. Shell Programming and Scripting

Count matching filenames in a folder

Hi all, I have 4 files for example named abc01012009.txt abc02012009.txt abc03012009.txt abc04012009.txt in a folder. I would like to firstly backup the latest file available, in this case, the latest date available, abc04012009.txt to its subfolder named backup, and then rename the... (4 Replies)
Discussion started by: tententen
4 Replies

4. Shell Programming and Scripting

count numbers of matching rows and replace its value in another file

Hello all, can you help me in this problem, assume We have two txt file (file_1 and file_3) one is file_1 contains the data: a 0 b 1 c 3 a 7 b 4 c 5 b 8 d 6 . . . . and I need to count the lines with the matching data (a,b,..) and print in new file called file_2 such as the... (4 Replies)
Discussion started by: GoldenFalcon10
4 Replies

5. Shell Programming and Scripting

awk: matching and not matching

Hello all, simple matching and if not match problem that i can't figure out. file1 hostname: 30 10 * * * /home/toto/start PROD instance_name1 -p 00 9 * * * /home/toto/start PROD instance_name2 -p 15 8 * * * /home/toto/start PROD instance_name3 -p hostname2: 00 8 * * *... (5 Replies)
Discussion started by: maverick72
5 Replies

6. Shell Programming and Scripting

Multiple pattern matching using awk and getting count of lines

Hi , I have a file which has multiple rows of data, i want to match the pattern for two columns and if both conditions satisfied i have to add the counter by 1 and finally print the count value. How to proceed... I tried in this way... awk -F, 'BEGIN {cnt = 0} {if $6 == "VLY278" &&... (6 Replies)
Discussion started by: aemunathan
6 Replies

7. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

8. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

9. Shell Programming and Scripting

Compare two files and count number of matching lines

Dear All, I would like to compare two files and return the number of matches found. Example File A Lx2 L1_Mus1 L1Md_T Lx5 L1M2 L1_Mus3 Lx3_Mus Lx9 Lx2A L1Md_A L1Md_F2 File B L1_Mus3 L1_Mus3 (3 Replies)
Discussion started by: paolo.kunder
3 Replies

10. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies
KOI8-U(7)						     Linux Programmer's Manual							 KOI8-U(7)

NAME
koi8-u - Ukrainian character set encoded in octal, decimal, and hexadecimal DESCRIPTION
RFC 2310 defines an 8-bit character set, KOI8-U. KOI8-U encodes the characters used in Ukrainian and Byelorussian. KOI8-U characters The following table displays the characters in KOI8-U that are printable and unlisted in the ascii(7) manual page. Oct Dec Hex Char Description ----------------------------------------------------------------------- 200 128 80 BOX DRAWINGS LIGHT HORIZONTAL 201 129 81 | BOX DRAWINGS LIGHT VERTICAL 202 130 82 BOX DRAWINGS LIGHT DOWN AND RIGHT 203 131 83 BOX DRAWINGS LIGHT DOWN AND LEFT 204 132 84 BOX DRAWINGS LIGHT UP AND RIGHT 205 133 85 BOX DRAWINGS LIGHT UP AND LEFT 206 134 86 BOX DRAWINGS LIGHT VERTICAL AND RIGHT 207 135 87 BOX DRAWINGS LIGHT VERTICAL AND LEFT 210 136 88 BOX DRAWINGS LIGHT DOWN AND HORIZONTAL 211 137 89 BOX DRAWINGS LIGHT UP AND HORIZONTAL 212 138 8A BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL 213 139 8B UPPER HALF BLOCK 214 140 8C LOWER HALF BLOCK 215 141 8D FULL BLOCK 216 142 8E LEFT HALF BLOCK 217 143 8F RIGHT HALF BLOCK 220 144 90 LIGHT SHADE 221 145 91 MEDIUM SHADE 222 146 92 DARK SHADE 223 147 93 TOP HALF INTEGRAL 224 148 94 BLACK SQUARE 225 149 95 BULLET OPERATOR 226 150 96 / SQUARE ROOT 227 151 97 ~~ ALMOST EQUAL TO 230 152 98 <= LESS-THAN OR EQUAL TO 231 153 99 >= GREATER-THAN OR EQUAL TO 232 154 9A NO-BREAK SPACE 233 155 9B BOTTOM HALF INTEGRAL 234 156 9C o DEGREE SIGN 235 157 9D 2 SUPERSCRIPT TWO 236 158 9E . MIDDLE DOT 237 159 9F -:- DIVISION SIGN 240 160 A0 BOX DRAWINGS DOUBLE HORIZONTAL 241 161 A1 BOX DRAWINGS DOUBLE VERTICAL 242 162 A2 BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE 243 163 A3 CYRILLIC SMALL LETTER IO 244 164 A4 CYRILLIC SMALL LETTER UKRAINIAN IE 245 165 A5 BOX DRAWINGS DOUBLE DOWN AND RIGHT 246 166 A6 CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I 247 167 A7 CYRILLIC SMALL LETTER YI (Ukrainian) 250 168 A8 BOX DRAWINGS DOUBLE DOWN AND LEFT 251 169 A9 BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE 252 170 AA BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE 253 171 AB BOX DRAWINGS DOUBLE UP AND RIGHT 254 172 AC BOX DRAWINGS UP SINGLE AND LEFT DOUBLE 255 173 AD CYRILLIC SMALL LETTER GHE WITH UPTURN 256 174 AE BOX DRAWINGS DOUBLE UP AND LEFT 257 175 AF BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE 260 176 B0 BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE 261 177 B1 BOX DRAWINGS DOUBLE VERTICAL AND RIGHT 262 178 B2 BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE 263 179 B3 CYRILLIC CAPITAL LETTER IO 264 180 B4 CYRILLIC CAPITAL LETTER UKRAINIAN IE 265 181 B5 BOX DRAWINGS DOUBLE VERTICAL AND LEFT 266 182 B6 CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I 267 183 B7 CYRILLIC CAPITAL LETTER YI (Ukrainian) 270 184 B8 BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL 271 185 B9 BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE 272 186 BA BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE 273 187 BB BOX DRAWINGS DOUBLE UP AND HORIZONTAL 274 188 BC BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE 275 189 BD CYRILLIC CAPITAL LETTER GHE WITH UPTURN 276 190 BE BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL 277 191 BF (C) COPYRIGHT SIGN 300 192 C0 CYRILLIC SMALL LETTER YU 301 193 C1 CYRILLIC SMALL LETTER A 302 194 C2 CYRILLIC SMALL LETTER BE 303 195 C3 CYRILLIC SMALL LETTER TSE 304 196 C4 CYRILLIC SMALL LETTER DE 305 197 C5 CYRILLIC SMALL LETTER IE 306 198 C6 CYRILLIC SMALL LETTER EF 307 199 C7 CYRILLIC SMALL LETTER GHE 310 200 C8 CYRILLIC SMALL LETTER HA 311 201 C9 CYRILLIC SMALL LETTER I 312 202 CA CYRILLIC SMALL LETTER SHORT I 313 203 CB CYRILLIC SMALL LETTER KA 314 204 CC CYRILLIC SMALL LETTER EL 315 205 CD CYRILLIC SMALL LETTER EM 316 206 CE CYRILLIC SMALL LETTER EN 317 207 CF CYRILLIC SMALL LETTER O 320 208 D0 CYRILLIC SMALL LETTER PE 321 209 D1 CYRILLIC SMALL LETTER YA 322 210 D2 CYRILLIC SMALL LETTER ER 323 211 D3 CYRILLIC SMALL LETTER ES 324 212 D4 CYRILLIC SMALL LETTER TE 325 213 D5 CYRILLIC SMALL LETTER U 326 214 D6 CYRILLIC SMALL LETTER ZHE 327 215 D7 CYRILLIC SMALL LETTER VE 330 216 D8 CYRILLIC SMALL LETTER SOFT SIGN 331 217 D9 CYRILLIC SMALL LETTER YERU 332 218 DA CYRILLIC SMALL LETTER ZE 333 219 DB CYRILLIC SMALL LETTER SHA 334 220 DC CYRILLIC SMALL LETTER E 335 221 DD CYRILLIC SMALL LETTER SHCHA 336 222 DE CYRILLIC SMALL LETTER CHE 337 223 DF CYRILLIC SMALL LETTER HARD SIGN 340 224 E0 CYRILLIC CAPITAL LETTER YU 341 225 E1 CYRILLIC CAPITAL LETTER A 342 226 E2 CYRILLIC CAPITAL LETTER BE 343 227 E3 CYRILLIC CAPITAL LETTER TSE 344 228 E4 CYRILLIC CAPITAL LETTER DE 345 229 E5 CYRILLIC CAPITAL LETTER IE 346 230 E6 CYRILLIC CAPITAL LETTER EF 347 231 E7 CYRILLIC CAPITAL LETTER GHE 350 232 E8 CYRILLIC CAPITAL LETTER HA 351 233 E9 CYRILLIC CAPITAL LETTER I 352 234 EA CYRILLIC CAPITAL LETTER SHORT I 353 235 EB CYRILLIC CAPITAL LETTER KA 354 236 EC CYRILLIC CAPITAL LETTER EL 355 237 ED CYRILLIC CAPITAL LETTER EM 356 238 EE CYRILLIC CAPITAL LETTER EN 357 239 EF CYRILLIC CAPITAL LETTER O 360 240 F0 CYRILLIC CAPITAL LETTER PE 361 241 F1 CYRILLIC CAPITAL LETTER YA 362 242 F2 CYRILLIC CAPITAL LETTER ER 363 243 F3 CYRILLIC CAPITAL LETTER ES 364 244 F4 CYRILLIC CAPITAL LETTER TE 365 245 F5 CYRILLIC CAPITAL LETTER U 366 246 F6 CYRILLIC CAPITAL LETTER ZHE 367 247 F7 CYRILLIC CAPITAL LETTER VE 370 248 F8 CYRILLIC CAPITAL LETTER SOFT SIGN 371 249 F9 CYRILLIC CAPITAL LETTER YERU 372 250 FA CYRILLIC CAPITAL LETTER ZE 373 251 FB CYRILLIC CAPITAL LETTER SHA 374 252 FC CYRILLIC CAPITAL LETTER E 375 253 FD CYRILLIC CAPITAL LETTER SHCHA 376 254 FE CYRILLIC CAPITAL LETTER CHE 377 255 FF CYRILLIC CAPITAL LETTER HARD SIGN NOTES
The differences from KOI8-R are in the hex positions A4, A6, A7, AD, B4, B6, B7, and BD. SEE ALSO
ascii(7), charsets(7), cp1251(7), iso_8859-5(7), koi8-r(7), utf-8(7) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2016-07-17 KOI8-U(7)
All times are GMT -4. The time now is 04:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy