awk: union regions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk: union regions
# 1  
Old 07-14-2010
awk: union regions

Hi all,

I have difficulty to solve the followign problem.

mydata:

StartPoint EndPoint
22 55
2222 2230
33 66
44 58
222 240
11 25
22 60
33 45

The union of above regions will turn out:

11-66,222-240,2222-2230

Can someone give suggest an efficient way to do this?

Thanks so much!
Phoeberunner
# 2  
Old 07-15-2010
Can't say I fully understand the requirement, but try...
Code:
$ cat file1
22 55
2222 2230
33 66
44 58
222 240
11 25
22 60
33 45

$ awk '{l=length($1);if(!SP[l]||$1<SP[l])SP[l]=$1;l=length($2);if($2>EP[l])EP[l]=$2}END{for(i in SP)print SP[i] "-" EP[i]}' file1|sort|paste -s -d ,
11-66,222-240,2222-2230

$

# 3  
Old 07-15-2010
perl should be easier to fulfill it

Code:
while(<DATA>){
	my @tmp=split;
	map {my $tmp=length($_); push @{$hash{$tmp}}, $_} @tmp;
}
foreach my $key(sort {$a<=>$b} keys %hash){
	my @tmp = sort @{$hash{$key}};
	print $tmp[0]," <-> ", $tmp[$#tmp],"\n";
}
__DATA__
22 55
2222 2230
33 66
44 58
222 240 
11 25
22 60
33 45
1 6
45678 12345

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Big and continuous regions

Hi all, I have a file like this I want to extract only those regions which are big and continous chr1 3280000 3440000 chr1 3440000 3920000 chr1 3600000 3920000 # region coming within the 3440000 3920000. so i don't want it to be printed in output chr1 3920000 4800000 chr1 ... (2 Replies)
Discussion started by: amrutha_sastry
2 Replies

2. Shell Programming and Scripting

Assigning the names from overlapping regions

I have 2 files; file 1 having smaller positions that overlap with the positions with positions in file2. file1 aaa 20 22 apple aaa 18 25 banana aaa 12 30 grapes aaa 22 25 melon file2 aaa 18 26 cdded aaa 10 35 abcde I want to get something like this output aaa 18 26 cdded banana... (4 Replies)
Discussion started by: anurupa777
4 Replies

3. Shell Programming and Scripting

Obtain the names of the flanking regions

Hi I have 2 files; usually the end position in the file1 is the start position in the file2 and the end position in file2 will be the start position in file1 (flanks) file1 Id start end aaa1 0 3000070 aaa1 3095270 3095341 aaa1 3100822 3100894 aaa1 ... (1 Reply)
Discussion started by: anurupa777
1 Replies

4. Programming

GDB and GCC union

My concept may sound a bit cryptic but I what some startup information as to how we can use GDB APIs / debugging techniques in programs with GCC when we compile the program. We can definitely tell gcc to link GDB libs also. The ultimate aid would be that when the compiled programs executes it... (4 Replies)
Discussion started by: uunniixx
4 Replies

5. Web Development

Intersection and union of array by hash

Hi, A piece of script from Perl-cookbook I do not understand, and post here for explanation. The purpose is to find the element in either array (union), and in both array (intersection). Thank you in advance. @a=qw(1 3 5 6 7 8); @b=qw(2 3 5 7 9); foreach $e (@a, @b) {$union{$e}++ &&... (3 Replies)
Discussion started by: yifangt
3 Replies

6. Shell Programming and Scripting

Text files union

How can i union two files that each of them contain text to one new file in unix shell scripting or in awk scripting language? (2 Replies)
Discussion started by: tal
2 Replies

7. Shell Programming and Scripting

union of two files

Given two files of the same format (For example number1|text1|number2) what is the command to print lines in file1 which do not occur in file2? diff command seems a bit complicated for me for this purpose. Please help!! Thank you very much. (3 Replies)
Discussion started by: sherkaner
3 Replies

8. Shell Programming and Scripting

How to find union of two files

Is there a command in unix to find the union of two files and removing the union from one of the files? e.g. I have two files input1.txt and input2.txt with the contents below: $ more input1.txt 4 2 3 2 $ more input2.txt 5 4 4 8 2 I want to find the union of the two and... (7 Replies)
Discussion started by: stevefox
7 Replies
Login or Register to Ask a Question