Making Large Connection nodes for Graph


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making Large Connection nodes for Graph
# 1  
Old 07-04-2009
Making Large Connection nodes for Graph

Hi power user,

Basically, this thread is a continuation of the previous one Smilie:

https://www.unix.com/shell-programmin...#post302326483

However, I'm going to explain it again.

I have this following data:

file1
aa A
aa B
aa C
bb X
bb Y
bb Z
cc O
cc P
cc Q
. .
. .
. .
. .

and I want to turn them into a connection nodes like this:
file2

A aa A
A aa B
A aa C
B aa C
B aa B
C aa C
X bb X
X bb Y
X bb Z
Y bb Z
Y bb Y
Z bb Z
. . .
. . .
. . .
. . .

I made this relation, to create a graph. The file have more than 6.000.000 lines.
For smaller files (100.000 lines), I have used this following script in the previous thread:

join -o 1.2 0 2.2 -1 1 -2 1 file1 file1 | nawk '!a[$3$2$1];{a[$1$2$3]++}'
join -o 1.2 0 2.2 -1 1 -2 1 file1 file1 | nawk '$1<$3{print;next}{print$3,$2,$1}' | sort -u
nawk '
NR==FNR { c = a[$1]; a[$1] = c?c" "$2:$2; next }
{ c = a[$1]
if (c) {
split(c,b)
for (k in b) {
p = $2<b[k]?$2" "$1" "b[k]:b[k]" "$1" "$2
if (!d[p]++) print p
}
}
}
' file1 file1
For small file, those three kind of scripts could create the network only in less than 10 minutes. However, for files with more than 6.000.000 lines, even after one days, there was no results at all Smilie. Is there any faster way to do it?


Any suggestion, how to create file2 by using perl or awk? Tx
# 2  
Old 07-06-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

Most notably, please use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Thank You.

The UNIX and Linux Forums
# 3  
Old 07-13-2009
Sorry for the mistakes. Now, I repaired the posting.

Hi power user,

Basically, this thread is a continuation of the previous one :

Making Connection nodes for Graph

However, I'm going to explain it again.

I have this following data:

file1
aa A
aa B
aa C
bb X
bb Y
bb Z
cc O
cc P
cc Q
. .
. .
. .
. .

and I want to turn them into a connection nodes like this:
file2

A aa A
A aa B
A aa C
B aa C
B aa B
C aa C
X bb X
X bb Y
X bb Z
Y bb Z
Y bb Y
Z bb Z
. . .
. . .
. . .
. . .

I made this relation, to create a graph. The file have more than 6.000.000 lines.
For smaller files (100.000 lines), I have used this following script in the previous thread:

Code:
join -o 1.2 0 2.2 -1 1 -2 1 file1 file1 | nawk '!a[$3$2$1];{a[$1$2$3]++}'

Code:
join -o 1.2 0 2.2 -1 1 -2 1 file1 file1 | nawk '$1<$3{print;next}{print$3,$2,$1}' | sort -u

Code:
nawk '
NR==FNR { c = a[$1]; a[$1] = c?c" "$2:$2; next }
{ c = a[$1]
if (c) {
split(c,b)
for (k in b) {
p = $2<b[k]?$2" "$1" "b[k]:b[k]" "$1" "$2
if (!d[p]++) print p
}
}
}
' file1 file1

For small file, those three kind of scripts could create the network only in less than 10 minutes. However, for files with more than 6.000.000 lines, even after one days, there was no results at all . Is there any faster way to do it?


Any suggestion, how to create file2 by using perl or awk? Tx
# 4  
Old 07-13-2009
Try...
Code:
awk '{n=++a[$1];b[$1,n]=$2}END{for(c in a)for(n=1;n<=a[c];n++)for(z=1;z<=n;z++)print b[c,z],c,b[c,n]}' file1|sort -k 2,2 -k 1,1 -k 3,3

Result...
Code:
A aa A
A aa B
A aa C
B aa B
B aa C
C aa C
X bb X
X bb Y
X bb Z
Y bb Y
Y bb Z
Z bb Z
O cc O
O cc P
O cc Q
P cc P
P cc Q
Q cc Q

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

2. Shell Programming and Scripting

Making Changes to large file in vi

so i have a large file that has many lines in it. i want to make changes (replace certain things) that are in a range of lines, but NOT the whole file. how do i do this? say for instance, if i want to change all the occurrences of the word "ramamama" to "ram cow welcome" in lines 9333 to... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. UNIX for Dummies Questions & Answers

One service, two nodes, HA

Hi all. I have two nodes taken different places. They are connected together on a network. So, i have a service, it works on one of nodes and when the node is unavailable the service should will be launched on other node. Solution: rhel cluster, keepalive, hearbeat...may be Carp but what if... (2 Replies)
Discussion started by: Flomaster
2 Replies

4. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

5. Shell Programming and Scripting

Making Connection nodes for Graph

Hi Power User, I have this following data: file1 aa A aa B aa C bb X bb Y bb Z cc O cc P cc Q . . . . . .... (4 Replies)
Discussion started by: anjas
4 Replies

6. HP-UX

FTP large files - Getting "Connection Refused"

Hello Friends, When i trying to transfer a huge amount of files via FTP to a HP-Unx server, I am getting an error "Connection Refused"...! How can i avoid this error. Regards, Prakash K:b: (4 Replies)
Discussion started by: bullz26
4 Replies

7. UNIX for Dummies Questions & Answers

problem while making ftp of a large file

Hi Friends, I'mfacing a problem while doing ftp of a large file.The control session is getting closed after sometime.But data session transfers the file successfully even when the control seeion is lost.I need to make the control session available as long as data session is active. How can i... (1 Reply)
Discussion started by: rprajendran
1 Replies

8. UNIX for Advanced & Expert Users

Managing nodes???

Does anyone know something about this? I have no idea what it means and how to do it. but if anyone can give me and explanation and also point me to a website, i'd really appreciate it (5 Replies)
Discussion started by: TRUEST
5 Replies

9. UNIX for Dummies Questions & Answers

nodes

how do you list all the nodes in unix :confused: (3 Replies)
Discussion started by: kamisi
3 Replies

10. UNIX for Dummies Questions & Answers

i-nodes

first off, i am new to unix so please bear with me. i was reading somewhere that if your i-nodes get critical that it can slow your network down. what are i-nodes and when do they become a critical number? this is what mine states: / (/dev/root ): 777058 blocks 569290 i-nodes... (4 Replies)
Discussion started by: djatwork
4 Replies
Login or Register to Ask a Question