Help with awk script to get missing numbers in column 1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk script to get missing numbers in column 1
# 8  
Old 11-05-2013
@ Ophiuchus I didn't get you...It should work if your real file is same like sample file

for example if I take sample file it's giving output..it would be better if you show us real input

Code:
$ cat file 
1,4
25,6
50,7
75,2
100,2

Code:
$ awk -F, '{while(++x<$1)print x}' file
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99


Last edited by Akshay Hegde; 11-05-2013 at 02:59 PM..
# 9  
Old 11-05-2013
try also:
Code:
awk -F, '{for (i=a+1; i<$1; i++) print i; a=$1}' file

# 10  
Old 11-05-2013
Hello Akshay Hegde,

I'm attaching the real column1, without any more columns and you can se that is being printed more lines than expected.


Hello rdrtx1,

It doesn't work with real attached file.

Thanks in advance for the help.
# 11  
Old 11-05-2013
in file.txt attached there are bad records, example:
Code:
 
(line #, value)
916084 62953736678539288
1092645 75087122368954400
1637717 7034045921763328
1722185 118349468948103173
3090566 13274083647037441
3321967 14267956259201025
4216020 289727116554141730
4807811 330395302886506496
4860863 334041077285781539
5051127 347116125965910039

# 12  
Old 11-05-2013
Hello rdrtx1,

Yes, there are those wrong values, then due to that I'd like to pre load an array of N consecutive elements to compare with column 1 to print only those that are missing, but I don't know how to pre load an array in that way.
# 13  
Old 11-05-2013
try something like:
Code:
awk -F, 'length($1)<8{for (i=a+1; i<$1; i++) print i; a=$1}' file.txt

This User Gave Thanks to rdrtx1 For This Post:
# 14  
Old 11-05-2013
Hello rdrtx1,

Thanks for the help. It seems to work fine. Is giving me 93 values and the counts it seems to be fine since:
NL = Number of lines = 5440172
LN = Last number in column 1 = 5440255
Wl = Wrong lines = 10

Then, (LN-NL)+Wl=83 + 10 = 93.

PS: May you explain me the logic of your program please.

Many thanks for your help!

Last edited by Ophiuchus; 11-05-2013 at 07:20 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

2. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies

3. UNIX for Dummies Questions & Answers

How to combine and insert missing consecutive numbers - awk or script?

Hi all, I have two (2) sets of files that are based on some snapshots of database that I want to merge and insert any missing sequential number. Below are example representation of these files: file1: DATE TIME COL1 COL2 COL3 COL4 ID 01/10/2013 0800 100 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

4. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

5. Shell Programming and Scripting

Fill missing numbers in second column with zeros

Hi All, I have 100 files with names like this: 1.dat, 2.dat, 3.dat until 100.dat. My dat files look like this: 42323 0 438939 1 434 0 0.9383 3434 120.23 3 234 As you can see in the second column, some numbers are missing. I want to fill those missing places with 0's in all... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

how to include the missing column in the original file using awk

Hi Experts, The content of the raw file: date,nomsgsent,nomsgnotdeliver,nomsgdelay 201003251000,1000,1,2 201003251000,900,0,0 201003251000,1450,0,0 201003251000,1230,0,0 However, sometimes, the column will missing in the raw files: e.g. date,nomsgsent,nomsgdelay... (8 Replies)
Discussion started by: natalie23
8 Replies

7. Shell Programming and Scripting

AWK processing -numbers to another column

Hi Guys, I'm trying to clean up my home logger file and can't seem to work this out. Here is my data: 10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 -49.1 220.9 10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0... (2 Replies)
Discussion started by: BeJay
2 Replies

8. Shell Programming and Scripting

trying to make an AWK code for ordering numbers in a column from least to highest

Hi all, I have a large column of numbers like 5.6789 2.4578 9.4678 13.5673 1.6589 ..... I am trying to make an awk code so that awk can easily go through the column and arrange the numbers from least to highest like 1.6589 2.4578 5.6789 ....... can anybody suggest, how can I do... (5 Replies)
Discussion started by: ananyob
5 Replies

9. Shell Programming and Scripting

ksh/awk help - output missing numbers

Here is what I am trying to do: I have a list of numbers that I pulled from an awk command in a column like so: 1 3 4 7 8 I want to find which numbers in the list are missing out of a range. So let's say I want to find out from the list above which numbers are missing from the... (6 Replies)
Discussion started by: afavis
6 Replies
Login or Register to Ask a Question