I want to override the child_value with the parent_value using awk. The solution must be generic applicable for larger data sources. The parent-record is defined by $1==$2.
This is my input file (format: ID;PARENT_ID;VALUE):
10;20;child_value
20;20;parent_value
This is the result I want:
10;20;parent_value
20;20;parent_value
This is my current approach:
awk -F\;
BEGIN {
OFS = FS
}
{
if ($1 == $2) {
mapping[$1] = $3
}
all[$1]=$0
}
END {
for (i in all) {
if (i[$3] == 'child_value') {
i[$3] = mapping[i]
}
print i
}
}
' file.in
Needless to say, that it doesn't work like that ;-) Anyone can help?
child_valueis constant or dynamic value ? Will it have more than one child-parent values ? If so, How to match parent and corresponding child ?5;10;typical_teen_value)? Does it getparent_valueorchild_value?