-
Notifications
You must be signed in to change notification settings - Fork 8
/
replace_invalid_values.awk
49 lines (39 loc) · 983 Bytes
/
replace_invalid_values.awk
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
#!/usr/bin/awk -f
#
# script to replace empty or null value fields that
# are unusable/unwanted, with a default value
#
# the result is an output file that does not contain any
# empty or null values anymore
#
#
# uwe.geercken@datamelt.com
# http://datamelt.com
#
# last update: 2009-05-11
#
#
BEGIN {
# the field seperator used during input
FS=";";
# the output field seperator
OFS=";";
# the default value for all invalid or empty values
DEFAULT_VALUE = "[undefined]";
}
# valid for all records of the input file - no filtering his done here
{
# we want to replace all empty fields of each row with the default value
# loop over the fields. awk starts counting at 1!
for(f=1;f<=NF;f++)
{
# check if one of the conditions is true
if($f == "null" || $f == "NULL" || $f == "Null" || $f == "" || $f == " " || $f == null || $f ~ /^~/)
{
# replace the invalid value with the default one
$f = DEFAULT_VALUE;
}
}
# print the record
print $0;
}