parsing a database with java


 
Thread Tools Search this Thread
Top Forums Programming parsing a database with java
# 1  
Old 03-29-2011
parsing a database with java

hi all
i have a databasewhich consists few fields in the form
Time(starting from 0 in asc order) bytes service flags protocols

e.g.
Code:
0, 0, 0, 56, 86
1, 524, 3, 6, 65
1, 624, 0, 43, 33
2, 72, 0, 43, 80
3, 26, 3, 6, 86
4, 323, 3, 1459, 95
5, 325, 3, 1459, 33
6, 225, 3, 1436, 57


now here in the window size of 2 seconds(here the time field) the pattern in the last column repeats the sequence 86-95-33 (The window size is 2 seconds in both the cases as you can see e.g 2-0=2 and 5-3=2)

so the output should be like the pattern of the field along with number of times it has been repeated throughout the table(there are around 50000 such records in the file)

Last edited by Franklin52; 03-30-2011 at 10:33 AM.. Reason: Please use code tags
# 2  
Old 03-29-2011
I still don't get it. Could you show an example of an output you would like to have? Also, why is the 1 second line repeated?
# 3  
Old 03-29-2011
Hi stuggler,

I'm not sure if you need to count how many times is repeated the sequence 86-95-33 in field 5 within the whole table, if so, try with:

Code:
echo "0, 0, 0, 56, 86
1, 524, 3, 6, 65
1, 624, 0, 43, 33
2, 72, 0, 43, 80
3, 26, 3, 6, 86
4, 323, 3, 1459, 95
5, 325, 3, 1459, 33
6, 225, 3, 1436, 57
7, 225, 3, 1436, 86
8, 225, 3, 1436, 57
9, 225, 3, 1436, 95
10, 225, 3, 1436, 33
11, 524, 3, 6, 86
12, 624, 0, 43, 95
13, 72, 0, 43, 33" | 
awk -F"," '$5~/86/{a=NR}
$5~/95/{b=NR}
$5~/33/{c=NR;if(a==b-1 && b==c-1) s++}END{print "Sequence is repeated",s,"times"}'
Sequence is repeated 2 times


Hope it helps,

Regards.
# 4  
Old 03-29-2011
thanks cgkmal
it works perfectly fine
but what if the sequence is not fixed one ?
I mean the final output must include all the patterns with their count which are repeated in particular time duration
is there any shell way to deal with that ?
thanks in advance
# 5  
Old 03-29-2011
Hi stuggler,

Great that works for you.

Quote:
Originally Posted by stuggler
but what if the sequence is not fixed one ?
I mean the final output must include all the patterns with their count which are repeated in particular time duration
May you show real sample and desired output?

Regards
# 6  
Old 03-30-2011
the output shud consist all such sequences which are repeated in the particular time slot

Also the sequence shud be displayed along with the count of the sequence occured in the time slot
# 7  
Old 03-30-2011
Hi stuggler,

I'm not sure if you need something as follow, if so try with:
Sample: (There are some interlaced sequences)

Code:
cat inputfile
0, 0, 0, 56, 11
1, 524, 3, 6, 74
1, 624, 0, 43, 33
2, 72, 0, 43, 80
3, 26, 3, 6, 86
4, 323, 3, 1459, 95
5, 325, 3, 1459, 33
6, 225, 3, 1436, 57
7, 225, 3, 1436, 86
8, 225, 3, 1436, 57
9, 225, 3, 1436, 95
10, 225, 3, 1436, 33
11, 524, 3, 6, 86
12, 624, 0, 43, 95
14, 72, 0, 43, 33
15, 72, 0, 43, 11
16, 72, 0, 43, 74
17, 225, 3, 1436, 33
18, 225, 3, 1436, 11
19, 225, 3, 1436, 74
20, 225, 3, 1436, 33

# 1-) Show all sequences of 3 consecutive numbers counting their occurrences.
Code:
awk 'BEGIN{print "Sequence Found|Occurrences";OFS="|"}
{a[NR]=$5;nr=NR}
{for(i=1;i<=nr-2;i++) S[i]=a[i]"-"a[i+1]"-"a[i+2]}
{for(j=1;j<=nr-2;j++) $1=sprintf("%s", S[j]);c[$1]++}
END{for (m in c) if(m~/-/) print m,c[m]}' inputfile
Sequence Found|Occurrences
33-86-95|1
57-95-33|1
74-33-80|1
33-11-74|2
57-86-57|1
95-33-57|1
80-86-95|1
95-33-86|1
86-57-95|1
95-33-11|1
74-33-11|1
86-95-33|2
11-74-33|3
33-57-86|1
33-80-86|1

# 2-) Show only sequences of 3 consecutive numbers with more than one occurrence.
Code:
awk 'BEGIN{print "Sequence Found|Occurrences";OFS="|"}
{a[NR]=$5;nr=NR}
{for(i=1;i<=nr-2;i++) S[i]=a[i]"-"a[i+1]"-"a[i+2]}
{for(j=1;j<=nr-2;j++) $1=sprintf("%s", S[j]);c[$1]++}
END{for (m in c) if(m~/-/ && c[m]>1) print m,c[m]}' inputfile
Sequence Found|Occurrences
33-11-74|2
86-95-33|2
11-74-33|3

Hope it helps,

Regards
This User Gave Thanks to cgkmal For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk parsing file to create a database

Hi Guys, I have a list a hotels stored in many different text files. This list is kept in the following format: 20/03 Hotel: The Bear Hotel Honey Street Woodstock UK Tel:+44-xxxxxx Rate: 100 21/03 Hotel: The Bush Hotel Nice Street Farnham (4 Replies)
Discussion started by: freddie50
4 Replies

2. Shell Programming and Scripting

CRON Job to copy database and replace existing database

I have a reseller account with hostgator, which means i have WHM and Cpanel. I have set up a staging environment for one of my wordpress installations (client website), which is essentially sitting at staging.domain.com (live site is at domain.com). The staging website is a complete copy of the... (1 Reply)
Discussion started by: nzrobert
1 Replies

3. Solaris

Can't create database after Oracle Database installation

I installed Oracle 10 software on Solaris 11 Express, everything was fine execpt I can't create database using dbca.rsp file. I populated file with following options. OPERATION_TYPE = "createDatabase" GDBNAME = "solaris_user.domain.com" SID = "solaris_user" TEMPLATENAME = "General... (0 Replies)
Discussion started by: solaris_user
0 Replies

4. Solaris

redirect solaris database from linux database..

hi.. i have a need .. my php runs on my linux redhat box with mysql.. i want my php code to refer another mysql database which is in solaris 10 x86... can u tell me the procedure .. how it can be done through php .. sorry am new to php... is it possible to redirect from linux mysql to... (7 Replies)
Discussion started by: senkerth
7 Replies

5. Programming

Need an c,c++,or java code for parsing the log files

need the code for c,c++,java for parsing the log file (5 Replies)
Discussion started by: raghuraipur
5 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

8. UNIX for Dummies Questions & Answers

Connection problem with gui java program to postgreaql database using unix

Having problem in connecting my gui java program to postgreaql database. I first used setenv classpath /home/share/postgresql/java/postgresql.jar:proj1, where proj1 is my folder conatining all java and class file, to set classpath. Then javac *.java. Then java proj1.Login. It gives me... (2 Replies)
Discussion started by: uci
2 Replies
Login or Register to Ask a Question