-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathh2020_latest_filter.awk
More file actions
executable file
·78 lines (65 loc) · 1.31 KB
/
Copy pathh2020_latest_filter.awk
File metadata and controls
executable file
·78 lines (65 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! usr/bin/awk -f
function is_empty(column) {
return (length(column) == 2)
}
function is_date(column) {
return column ~ /[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}/
}
function is_url(column) {
return column ~ /(www|http:|https:)+[^\s]+[\w]/
}
function is_rcn(column) {
return column ~ /[0-9]{1,3}\.[0-9]+/
}
function is_recent_update(date_string, LR) {
_date = date_string
gsub(/"/, "",_date)
return (LR <= _date)
}
# function correct_index(column, idx, row) {
# if (is_url(column)) {
# $idx = column = $(idx + 1)
# print "corrected column? " $idx
# } else if (is_rcn(column)) {
# $idx = column = $(idx - 1)
# }
# }
BEGIN {
FS = ","
dummy = "0000-00-00 00:00:00"
dummy_length = length(dummy)
error_rows[0] = "ERROR_ROWS"
}
#main loop
{
# print headers
if (NR == 1)
print;
else {
dt = $CUD;
# skip lines with empty update date
if (is_empty(dt))
getline;
# rounds = 0
# while(! is_date(dt)) {
# rounds++;
# if(rounds > 2){
# break
# }
# correct_index(dt, CUD, $0)
# }
if(! is_date(dt)) {
idx = length(error_rows)
error_rows[idx] = $0
} else if(is_recent_update(dt, LR)) {
print
}
}
}
END {
print error_rows[0] > "error_rows.txt"
err_length = length(error_rows)
for(i=1; i<err_length; i++){
print error_rows[i] >> "error_rows.txt"
}
}