Dealing with edge-list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dealing with edge-list
# 1  
Old 04-23-2014
Dealing with edge-list

I have an edge-list with nodes, edge.txt
Code:
A  B 
B  J 
J  H 
C  A 
G  H 
G  A
A  C
K  G

I have another file which tells me which of these nodes are important, input.txt

Code:
G
C
A

I want to filter only those rows which have the important nodes in "both columns"
desired output, without any repeated entries:
Code:
C  A
G  A

# 2  
Old 04-23-2014
Code:
awk 'FNR==NR {a[$0]++;next}{if ($1 in a && $2 in a) {print}}' input.txt edge.txt

This would output:

C A
G A
A C

Are you considering "C A" and "A C" as duplicates? Even though they are the other way round? If so, I will change the code.
# 3  
Old 04-24-2014
Thanks, yea I am considering CA and AC as duplicates
# 4  
Old 04-24-2014
Try:
Code:
awk '
FNR == NR {
	a[$1]
	next
}
$1 in a && $2 in a {
	if(!($1 FS $2 in p) && !($2 FS $1 in p)) {
		print $1, $2
		p[$1 FS $2]
	}
}' input.txt edge.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two edge list

Hello, I have two network edgelists with first two columns as nodes and the last column pearson correlation coefficient (PCC). I want to remove the edges from net1 whose edges are common with net2 && (PCC)net2>=(PCC)net1 net1.txt A B 0.6 A C 0.7 B C 0.7 D C ... (1 Reply)
Discussion started by: Sanchari
1 Replies

2. Web Development

Set Edge Compatibility Mode for IE

hi i have code in iplanet webserver in obj.conf file <If $uri !~'^/app/literature/item/(.*)'> AuthTrans fn="set-variable" insert-srvhdrs="X-UA-Compatible:IE=EmulateIE8" </If> i want to migrate it to apache webserver need your help to replace the above code for apache webserver. i... (0 Replies)
Discussion started by: raghur77
0 Replies

3. UNIX for Dummies Questions & Answers

Dealing with sum

I have file input 1/1/2013 1AS030A 0 1083 CHINA 1/1/2013 1AS030B 0 675 KOREA 1/1/2013 1AS035A 162 662 CHINA 1/1/2013 1AS035B 51 799 INDIA 1/1/2013 1AS035C 0 731 CHINA 1/2/2013 1AS073A 10 1375 KOREA... (5 Replies)
Discussion started by: radius
5 Replies

4. Infrastructure Monitoring

Cutting edge IT software - what's out there and what do you use

I am sys admin for many servers running unix (solaris, HP, Linux) and also some windows server and solaris x86 I want to know what leading software is out there whether it be freeware, shareware or commercial that can do things listed: Performance monitoring (hardware/software, disk usage,... (7 Replies)
Discussion started by: frustrated1
7 Replies

5. Shell Programming and Scripting

Help in dealing with arra

I am readinga file lin by line and based craeting a arry of unique elemenst from the second column of the line. However when i coem out of the while loop my array becomes empty , can eny one tell me what I would be doing wrong #!/bin/bash logfile="./mylog.dat" begin=100 end="$(( $begin +... (5 Replies)
Discussion started by: jojan
5 Replies
Login or Register to Ask a Question