picking the numbers missing which is supposed to be a numercal/counting order


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting picking the numbers missing which is supposed to be a numercal/counting order
# 1  
Old 05-05-2011
picking the numbers missing which is supposed to be a numercal/counting order

Hi,

I have a tab delimited file with 2 columns. In the first column the numbers are sorted from smallest to largest. It is supposed to be in the numerical order but in between some numbers are missing. Is there a way I could easily get those numbers that are missing and output it a file using awk or sed. I can specify the lowest and the largest number.

Please let me know
# 2  
Old 05-05-2011
Not that great but:
Code:
>cat /tmp/a
1
2
3
5
6
9
10
>cat /tmp/b
1
2
3
4
5
6
7
8
9
10
>grep -v -f /tmp/a /tmp/b
4
7
8

# 3  
Old 05-05-2011
Thanks But there is only one file no 2 files
# 4  
Old 05-05-2011
I know. You'll have to make a second file, including all the numbers from low to high.
# 5  
Old 05-05-2011
Code:
awk -v l=$low -v h=$high '{a[$1]=$1;next} END{for(i=l;i<=h;i++) if(i in a) { ;} else { print i}}' file


Last edited by panyam; 05-05-2011 at 12:49 PM.. Reason: Cahnged as per requirement
# 6  
Old 05-05-2011
Thanks for the reply...but I think its not working properly. The file contains 2 columns and I need the first column only to count. My lowest value was 64 and I got values lower than that and even including 64 itself. I think we are close enough to the solution
# 7  
Old 05-05-2011
Check my new changed code in the last post..If it wont work , paste the i/p and o/p extected ( atleast few rows )

Regards
Ravi
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to takes the missing files in ascending order

Hi am using unix aix we have a lots of files which comes from server and fetch in one directory. the files will be in the format as File name as : ------------- pprr0103 (01 as date and 03 as month) pprr0203 pprr0603 ... ... pprr3103 pprr0304 Outputs:- Missing files as... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

2. Shell Programming and Scripting

sed&awk: replace lines with counting numbers

Dear board, (I am trying to post this the 3rd time, seems there's some conflicts with my firefox with this forum, now use IE) ------ yes, I have searched the forum, but seems my ? is too complicated. ------------origianl file --------------- \storage\qweq\ertert\ertert\3452\&234\test.rec... (4 Replies)
Discussion started by: oUo
4 Replies

3. UNIX for Dummies Questions & Answers

Appending a column of numbers in ascending order to a text file

I have a text file where I want to append a column of numbers in ascending orders. Input: 57 abc 25 def 32 ghi 54 jkl Output:57 abc 57 abc 1 25 def 2 32 ghi 3 54 jkl 4 How do I go about doing that? Thanks! (11 Replies)
Discussion started by: evelibertine
11 Replies

4. Programming

generating pair of numbers in special order

I need some help in generating pair of numbers in orders using FORTRAN code. The order is like following. loop_1: 1,2 2,3 3,4 4,5 5,6 6,7 7,8 ..... until <= 2000 loop_2: 1,3 3,5, 5,7 7,9 9,11 11,13 ........until <= 2000 loop_3: 1,4, 4,7 7,10 10,13 13,17 ..... until... (3 Replies)
Discussion started by: vjramana
3 Replies

5. Shell Programming and Scripting

counting the numbers in a row

File A aa <space> --D--A--D---DDY---M--UM-M--MY Another file D3 M9 So output shud be Here in FileA D which is 3 after removing dash after we have counted dash D is position at 9 and for M is 23 final output will be D9 M23 (2 Replies)
Discussion started by: cdfd123
2 Replies

6. UNIX for Dummies Questions & Answers

Help required on Printing of Numbers, which are missing in the range

Hi Experts, Need help on printing of numbers, which are missing in the range. Pls find the details below Input 1000000002 1000000007 1234007940 1234007946 Output 1000000003 1000000004 1000000005 1000000006 1234007941 (2 Replies)
Discussion started by: krao
2 Replies

7. Shell Programming and Scripting

Ascending & Descending order numbers

Dear All, I have below attached file in which i have many nos, i want the last ascending order nos. The brief description is given below. File 315 381 432 315 381 432 315 381 432 315 381 432 315 381 432 (6 Replies)
Discussion started by: pravani1
6 Replies

8. Shell Programming and Scripting

Fill in missing numbers in range

I need to edit a list of numbers on the following form: 1 1.0 2 1.4 5 2.1 7 1.9 I want: 1 1.0 2 1.4 3 0.0 4 0.0 5 2.1 6 0.0 7 1.9 (i want to add the missing number in column 1 together with 0.0 in column 2). I guess it is rather trivial but i didn't even manage to read column... (5 Replies)
Discussion started by: bistru
5 Replies
Login or Register to Ask a Question