hpr-tools/InternetArchive/parse_ia.awk

42 lines
1.1 KiB
Awk
Raw Normal View History

#!/usr/bin/awk -f
#-------------------------------------------------------------------------------
# Process tab-delimited data from the Internet Archive with a field name
# header, reporting particular fields. The algorithm is general though this
# instance is specific.
#
# This script is meant to be used thus:
# $ ia list -va hpr2450 | ./parse_ia.awk
# hpr2450.flac derivative
# hpr2450.mp3 derivative
# hpr2450.ogg derivative
# hpr2450.opus original
# hpr2450.spx original
# hpr2450.wav original
#
#-------------------------------------------------------------------------------
BEGIN {
FS = "\t"
}
#
# Read the header line and collect the fields into an array such that a search
# by field name returns the field number.
#
NR == 1 {
for (i = 1; i <= NF; i++) {
fld[$i] = i
}
}
#
# Read the rest of the data, reporting only the lines relating to chosen files
# and print the fields 'name' and 'source'
#
NR > 1 && $(fld["source"]) ~ /original/ {
printf "%-25s %s\n",$(fld["name"]),$(fld["source"])
}
# vim: syntax=awk:ts=8:sw=4:ai:et:tw=78:nu:rnu: