Determine differient IP in a very long record.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Determine differient IP in a very long record.
# 8  
Old 06-22-2009
See the addition in my previous post. Use it like this:

Code:
./scriptname inputfile

# 9  
Old 06-22-2009
Quote:
Originally Posted by radoulov
See the addition in my previous post. Use it like this:

Code:
./scriptname inputfile

Thanks Smilie

---------- Post updated at 02:29 PM ---------- Previous update was at 02:11 PM ----------

Hi Radoulov,

Code:
[root@localhost ~]# cat aaaa
312009 1 0620233743 0620233748 20090620235854 20.7.22.14 aaa
312009 2 0620233743 0620233748 20090620235854 20.7.22.14 aaa
312009 3 0620233743 0620233748 20090620235854 20.7.22.14 aaa
312009 5 0620233743 0620233748 20090620235854 21.7.22.14 aaa
312009 2 0620233743 0620233748 20090620235854 20.7.22.14 aaa
[root@localhost ~]# cat a.pl
#!/usr/bin/perl
use strict;
use warnings;
my %x;
my @F;
open(my $FB, "/root/aaaa") or die "$!";
while (<$FB>) {
  my @F = split;
  $x{$F[5]} += $F[1];
}
print map "$_ $x{$_}\n", sort { $x{$b} <=> $x{$a} } keys %x;
close $FB;
[root@localhost ~]# ./a.pl
20.7.22.14 8
21.7.22.14 5
[root@localhost ~]#

If I would like to have the result of:
20.7.22.14 8 4
21.7.22.14 5 1
Total: 13

Code:
##############
4 and 1 is kind of "cat aaaa | grep 20.7.22.14 | wc -l".
Total: 13 is 8+5=13.

Please advice how i can add this new result into your script. Smilie Thanks

Last edited by radoulov; 06-24-2009 at 03:20 PM.. Reason: added code tags
# 10  
Old 06-24-2009
Found the solution aly

Code:
[root@localhost ~]# cat a.pl
#!/usr/bin/perl
use strict;
use warnings;
my %x;
my %xx;
my @F;
open(my $FB, "/root/aaaa") or die "$!";
while (<$FB>) {
my @F = split;
$x{$F[5]} += $F[1];
$xx{$F[5]} += 1;
}
print map "$_ $xx{$_} $x{$_}\n", sort { $x{$b} <=> $x{$a} } keys %x;
close $FB;

So $xx value is the one to count how many lines.

Last edited by radoulov; 06-24-2009 at 03:19 PM.. Reason: added code tags
# 11  
Old 06-24-2009
Quote:
Originally Posted by jimmy_y
Code:
$xx{$F[5]} += 1;

Or just:

Code:
++$xx{$F[5]};

Glad you found the solution yourself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Long file record

riends I have the following problem: test.txt I have a file that has the following contents: is a fixed-length file to the end of the number 12 has spaces, so that it is fixed length 123456789 123456789 123456789 12 This code shows me the length of each record, but in... (2 Replies)
Discussion started by: tricampeon81
2 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. UNIX for Dummies Questions & Answers

awk: record too long

Hi All , I am getting record too long for the below command . nawk -F\" '{a=a" "$2} END{for(i in a) print i,a }' test|sort|awk '{for(i=1;i<=NF;i++) t=t"\t"$i;if(NF>max)max=NF} END{for(i=1;i<=max;i++)print t }' File test has 850 records ... Please help.. (2 Replies)
Discussion started by: saj
2 Replies

4. Shell Programming and Scripting

Record too long error while running awk

I have written below script to add substring in a file containing fixed length record, but when I run below script I get error as: ERROR: awk: record `22503004502488344040...' too long My fixed length record has length around 2000, each file is having 5000 records and total number of files is... (3 Replies)
Discussion started by: Devesh5683
3 Replies

5. Shell Programming and Scripting

determine the active processes on the system which are running since long time

Hi , Please help me shell script to determine the active processes on the system which are running since long time (2 Replies)
Discussion started by: itian2010
2 Replies

6. Shell Programming and Scripting

plus values from two files differient fields.

Hi Everyone, I have two files: filea: Sun Jun 21 14:37:56 2009 1 2 3 Sun Jun 21 11:47:16 2009 2 3 4 fileb: Sun Jun 21 14:37:56 2009 1 2 3 Sun Jun 21 11:47:17 2009 33 44 55 The output is filec: Sun Jun 21... (4 Replies)
Discussion started by: jimmy_y
4 Replies

7. Shell Programming and Scripting

plus values from two files in differient rows

Hi Guys :), I have two files. filea: 12:20:23 4 12:21:23 3 12:22:23 2 12:25:23 3 fileb: 11:20:23 4 12:21:23 3 12:22:23 2 12:26:23 3 12:30:23 3 The result will be: 11:20:23 4 12:20:23 4 (3 Replies)
Discussion started by: jimmy_y
3 Replies

8. Shell Programming and Scripting

Split long record into csv file

Hi I receive a mainframe file which has very long records (1100 chars) with no field delimiters. I need to parse each record and output a comma delimited (csv) file. The record layout is fixed. If there weren't so many fields and records I would read the file into Excel, as a "fixed width"... (10 Replies)
Discussion started by: wvdeijk
10 Replies

9. Shell Programming and Scripting

Record Length too long -- AWK Problem

Hi All, I have a txt file which is an export of a query result from the database. The txt file contains 'Processid#sqlquery' from the database table.As the sqlquery is too long.... i am unable to get the fields seperated using the awk script as below:- cat sql.txt | awk -F'#' '{printf $2}'... (2 Replies)
Discussion started by: venkatajay_18
2 Replies

10. UNIX for Dummies Questions & Answers

Record too long for awk

I am trying to generate a small report with the help of awk. The contents are present in a file whose last line is very long. I can't shorten this line as its generated after a lot of processing. On reading this file awk says record "starting of line ..." too long record number 30 Now... (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies
Login or Register to Ask a Question