| 1 |
#!/usr/bin/awk -f |
| 2 |
|
| 3 |
# Public domain notice for all NCBI EDirect scripts is located at: |
| 4 |
# https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice |
| 5 |
|
| 6 |
# Author: Aaron Ucko |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
FS = "\t" |
| 10 |
} |
| 11 |
(NR <= 2) { |
| 12 |
for (c = 1; c <= NF; ++c) { |
| 13 |
data[NR,c] = $c |
| 14 |
# Subsequent rows will be populated lazily. |
| 15 |
} |
| 16 |
} |
| 17 |
(NR > 2) { |
| 18 |
for (c = 1; c <= NF; ++c) { |
| 19 |
if ( !(c in interesting) && $c != data[2,c] ) { |
| 20 |
interesting[c] = 1 |
| 21 |
# Belatedly fill in data for this column in previous rows. |
| 22 |
for (r = 3; r < NR; ++r) { |
| 23 |
data[r,c] = data[2,c] |
| 24 |
} |
| 25 |
} |
| 26 |
if (c in interesting) { |
| 27 |
data[NR,c] = $c |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
END { |
| 32 |
for (r = 1; r <= NR; ++r) { |
| 33 |
l = "" |
| 34 |
for (c = 1; c <= NF; ++c) { |
| 35 |
if (c in interesting) { |
| 36 |
l = l "\t" data[r,c] |
| 37 |
} |
| 38 |
} |
| 39 |
print substr(l, 2) # Leave off initial tab. |
| 40 |
} |
| 41 |
} |