awk '
$2 in A {
A[$3]=A[$2]
next
}
$3 in A {
A[$2]=A[$3]
next
}
{
A[$2]=A[$3]=$1
}
END {
for(i in A) B[A[i]]=B[A[i]] i FS
for(i in B) print i, B[i]
}
' file
Output:
Code:
R1 2 3 4 8 1
R5 5 6 7
R8 9 10
But this does not address yet when two separate chains are linked by a new pair...
Last edited by Scrutinizer; 04-10-2015 at 03:44 AM..
This User Gave Thanks to Scrutinizer For This Post:
awk '
$2 in A {
o=A[$3];
for(i in A) if (A[i]==o) A[i]=A[$2]
next
}
$3 in A {
A[$2]=A[$3]
next
}
{
A[$2]=A[$3]=$1
}
END {
for(i in A) B[A[i]]=B[A[i]] i FS
for(i in B) print i, B[i]
}
' file
This User Gave Thanks to Scrutinizer For This Post:
Hello to the experts! I have a file that I'd like to collapse based on a common ID column, separated by a character delimiter.
example input
a 1 6 word1 uniq1
b 2 7 WORD2 uniq2
b 2 7 WORD2 uniq3
b 2 7 WORD2 uniq4
c 3 8 word4 uniq5
d 4 9 word5 uniq6
e 5 1 word6 uniq7
desired output
a 1... (3 Replies)
Hi,
We have 2 UNIX Servers, say test1 and test2. Here, if I create a file or folder/delete a file or folder in the 1st server, it gets reflected automatically in the 2nd server.
I don't think any links are established between these 2 servers. Both these have 2 different hostnames.
How... (1 Reply)
any way i can block edit a program ?
i wrote a macro to do it in emacs
so it works like :
void foo ( int ... ) ; // collapsed.
it moves the body to temperary buffer, but i can't rely on this :( (2 Replies)
Hi friends,
i have a dynamically linked file on my solaris system.this is script that runs regularly. How can i read the contents of that ?
when i tried to say "vi filename " then it says executable and nothing is seen.
Please help.
thanks in advance
Veera (5 Replies)