The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
i-nodes - out of disk space on /tmp bblondin AIX 4 01-24-2009 08:36 PM
Shell script to map XML nodes mark14 Shell Programming and Scripting 1 03-25-2008 01:51 PM
Managing nodes??? TRUEST UNIX for Advanced & Expert Users 5 03-21-2003 05:47 AM
nodes kamisi UNIX for Dummies Questions & Answers 3 05-30-2002 04:47 PM
i-nodes djatwork UNIX for Dummies Questions & Answers 4 09-25-2001 01:29 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
anjas anjas is offline
Registered User
  
 

Join Date: Mar 2009
Location: Bali, Indonesia
Posts: 17
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 (permalink)  
Old 05-26-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
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 (permalink)  
Old 05-26-2009
anjas anjas is offline
Registered User
  
 

Join Date: Mar 2009
Location: Bali, Indonesia
Posts: 17
Tx for the answer. I have tried the first script, and it worked great
  #4 (permalink)  
Old 05-26-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
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 (permalink)  
Old 06-18-2009
anjas anjas is offline
Registered User
  
 

Join Date: Mar 2009
Location: Bali, Indonesia
Posts: 17
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
Reply

Bookmarks

Tags
connection, graph, nodes

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0