finding distance between numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding distance between numbers
# 1  
Old 03-15-2012
finding distance between numbers

Hi,

I have a file as


Code:
ABC 1634230,1634284,1634349,1634468 1634272,1634301,1634356,1634534

What I want is to find distance between the numbers.. column 1 is the gene name and column 2 are starts and column 3 are their respective stops for the starts. So what I want is column 3 which has +1 added to each value in column 2 except for the last value and -1 subtracted to each value except for the 1st value in column 1..

output:

Code:
 ABC 1634230,1634284,1634349,1634468  1634272,1634301,1634356,1634534 1634283,1634348,1634467 1634273,1634302,1634357

I have 40,000 such rows

Thanks,
# 2  
Old 03-15-2012
Code:
$
$
$ cat f37
ABC 1634230,1634284,1634349,1634468 1634272,1634301,1634356,1634534
PQR 10,9,8,7 1,2,3,4
$
$
$ perl -ane '@x = map {$_ - 1} split/,/, $F[1];
             @y = map {$_ + 1} split/,/, $F[2];
             printf ("%s %s %s\n", "@F", join(",", @x[1..$#x]), join(",", @y[0..$#y-1]))
            ' f37
ABC 1634230,1634284,1634349,1634468 1634272,1634301,1634356,1634534 1634283,1634348,1634467 1634273,1634302,1634357
PQR 10,9,8,7 1,2,3,4 8,7,6 2,3,4
$
$

tyler_durden
# 3  
Old 03-16-2012
Code:
awk -F'[ ,]' '{print $0" "$3-1","$4-1","$5-1" "$6+1","$7+1","$8+1}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

finding lowest numbers

i want to basically get the lowest numbers from a list ... for example my input file is .... 1 2 3 6 7 8 9 10 11 13 Now i want to create a script or a one liner which i can use like this ... for example ..../getlowest 3 --> this gives me the next 3 lowest numbers which... (6 Replies)
Discussion started by: greycells
6 Replies

2. UNIX for Dummies Questions & Answers

Finding numbers in lines with strings and number and doing some manipulation

Hi, I want to write a script that does something like this: I have a file, in which in every line, there is a string of words, and followed by some space, a number. Now, I want to identify the line, which has the largest startFace number (say m=8118), take that number and add it to the... (2 Replies)
Discussion started by: super_commando
2 Replies

3. Shell Programming and Scripting

finding common numbers (contents) across 2 or 3 files

I have 3 files which are tab delimited and have numbers in it. file 1 1 2 3 4 5 6 7 File 2 3 5 7 8 File 3 1 (4 Replies)
Discussion started by: Lucky Ali
4 Replies

4. Shell Programming and Scripting

Finding occurences of numbers

I have two files The first file is in following format 5 937 8 1860 5 1 683 2 1 129 2 2 5 938 8 1122 5 1 20 520 4 1860 1851 1 5 939 8 1122 1124 1 20 521 4 5883 14 6 1860 1852 1 683 4 2 (5 Replies)
Discussion started by: stuggler
5 Replies

5. Shell Programming and Scripting

Finding the sum of two numbers

cat *.out |grep "<some text>" | awk '{print $6}' For ex,This will reutrn me 11111 22222 is it possible to add these two numbers in the above given command itself?I can write this to a file and find the sum. But I prefer to this calculation in the above given line itself. Any... (3 Replies)
Discussion started by: prasperl
3 Replies

6. UNIX for Dummies Questions & Answers

finding files with numbers in the file name???

Hello all, New to this forum! I got a Q: i want to find all files with numbers in the file name. e.g. blabla234.pm or fool654.pl action i took: ls | egrep '+' ls | egrep ls | egrep + ls | egrep '' ls | egrep '(+)' ls | egrep '()' ls | egrep '(.*.*)' ls | egrep '.*.*' ls | grep... (2 Replies)
Discussion started by: RedGrinGo
2 Replies

7. Programming

Converting distance list to distance matrix in R

Hi power user, I have this type of data (distance list): file1 A B 10 B C 20 C D 50I want output like this # A B C D A 0 10 30 80 B 10 0 20 70 C 30 20 0 50 D 80 70 50 0 Which is a distance matrix I have tried... (0 Replies)
Discussion started by: anjas
0 Replies

8. Shell Programming and Scripting

Need help in finding and replacing port numbers.

Hi All, I am trying to write a shell script which firstly will search some files and then increase the port numbers mentioned in them by a certain no. let me clear it with an example- suppose there r few files a,b,c,d.... file a's content- <serverEntries xmi:id="ServerEntry_1"... (3 Replies)
Discussion started by: ankushsingh10
3 Replies

9. Shell Programming and Scripting

generating random numbers with hamming distance 4

Hi I want to genrate 10 random 32 bit binary numbers with hamming distance 4 and 8. 11010110010101010101010101010101 11010110010101010100010101010010 if we look carefully at these two binary numbers they differ at 4 places hence hamming distance 4. Now I want to genrate these numbers... (2 Replies)
Discussion started by: hack_tom
2 Replies

10. IP Networking

finding port numbers

hither! whatz the command to find which process is using a specific port number? for example, port 8082? (3 Replies)
Discussion started by: darkcastle
3 Replies
Login or Register to Ask a Question