mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-19 09:24:14 +00:00
26 lines
516 B
Text
26 lines
516 B
Text
# First pass:
|
|
# Remember all unique key names:
|
|
for (k in $*) {
|
|
@all_keys[k] = 1;
|
|
}
|
|
# Remember all input records:
|
|
@records[NR] = $*;
|
|
|
|
# Second pass:
|
|
end {
|
|
for (nr in @records) {
|
|
# Get the sparsely keyed input record:
|
|
irecord = @records[nr];
|
|
# Fill in missing keys with empty string:
|
|
map orecord = {};
|
|
for (k in @all_keys) {
|
|
if (haskey(irecord, k)) {
|
|
orecord[k] = irecord[k];
|
|
} else {
|
|
orecord[k] = "";
|
|
}
|
|
}
|
|
# Produce the output:
|
|
emit orecord;
|
|
}
|
|
}
|