Making Connection nodes for Graph


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making Connection nodes for Graph
# 1  
Old 05-26-2009
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
. .
. .
. .
. .

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 could have more than 100.000 lines. Any suggestion, how to create file2 by using perl or awk? Tx
# 2  
Old 05-26-2009
Code:
join -o 1.2 0 2.2 -1 1 -2 1 file1 file1 | nawk '!a[$3$2$1];{a[$1$2$3]++}'

This may perform better (or not) with a large file1:

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


Last edited by colemar; 05-26-2009 at 11:11 AM..
# 3  
Old 05-26-2009
Tx for the answer. I have tried the first script, and it worked great Smilie
# 4  
Old 05-26-2009
Also doing even the join work in awk:
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

# 5  
Old 06-18-2009
Tx for the scripts. However, I have another problem, which is related to the previous one. For example, if I have this file:

file1
aa A 3
aa B 4
aa C 5
bb X 6
bb Y 7
bb Z 8
cc O 9
cc P 10
cc Q 11
. .
. .
. .
. .

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

A aa A 3 3
A aa B 3 4
A aa C 3 5
B aa C 4 5
B aa B 4 4
C aa C 5 5
X bb X 6 6
X bb Y 6 7
X bb Z 6 8
Y bb Z 7 8
Y bb Y 7 7
Z bb Z 8 8
. . .
. . .
. . .
. . .

I made this relation, to create a graph. Like before, The file could have more than 100.000 lines. Any suggestion to modify the script, or to create a new one? Tx
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

Remove duplicate nodes

Hi all, I have a list of node pairs separated with a comma and also, associated with their respective values. For example: b0015,b1224 1.1 b0015,b2576 1.4 b0015,b3162 2.5 b0528,b1086 1.7 b0528,b1269 5.4 b0528,b3602 2.1 b0948,b2581 3.2 b1224,b0015 1.1... (8 Replies)
Discussion started by: AshwaniSharma09
8 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. High Performance Computing

request more nodes

I am new to cluster commands. But I have tried utilizing: -pe, but I do not know my parallel computing environment. We are running SGE, is there a simpler command to request more nodes? also: qsub -N auto -M name@email.com -m abe auto.sh does not email me at all. Help would be appreciated (0 Replies)
Discussion started by: theawknewbie
0 Replies

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

6. UNIX for Advanced & Expert Users

Connection reset by peer..closing connection

Hello I'm facing the above problem while doing a performance run. I've a script which I'm launching from my windows desktop using mozilla. The script will invoke backend action on a Solaris host which in turn feeds the records to a driver located on a linux box(Cent OS). What's happening is... (1 Reply)
Discussion started by: subramanyab
1 Replies

7. Shell Programming and Scripting

Making Large Connection nodes for Graph

Hi power user, Basically, this thread is a continuation of the previous one :): https://www.unix.com/shell-programming-scripting/110650-making-connection-nodes-graph.html#post302326483 However, I'm going to explain it again. I have this following data: file1 aa A ... (3 Replies)
Discussion started by: anjas
3 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