Sponsored Content
Full Discussion: parsing a database with java
Top Forums Programming parsing a database with java Post 302509468 by cgkmal on Wednesday 30th of March 2011 10:29:04 PM
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:
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy