summaryrefslogtreecommitdiff
path: root/bibsum
blob: 6ffca61ab05f65002971d2e3043417e6dd96f0c8 (plain)
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
#!/bin/sh

#
# Print summaries of bibtex entries in tsv format given as input
# showing only the requested fields 
#

if [ $# -lt 1 ]; then 
	printf "Usage: %s <field> [<field>...]\n" $0
	exit 1;
fi

fields=$(echo "$@" | sed -E 's/([a-zA-Z0-9]+)/^\[\[:blank:\]\]*\1.\*=|/g;s/\ //g')
fields=$(echo "$fields" | sed -E 's/\|$//')

##echo "$fields"

IFS='
'

while read -r line; do
	line=${line##[[:blank:]]}
	if [ -n "$line" ]; then 
		name=$(echo "$line" | cut -f 1) 
		attrall=$(echo "$line" | cut -f 2-)
		attrs=$(echo "$line" | tr '\t' '\n' | sort | grep -aEi "($fields)" | \
		    tr '\n' '\t' | sed -E 's/\ +/ /g;s/\t+/\t/g')
		printf "%s\t%s}\n\n" $name $attrs
	fi
done