about summary refs log tree commit diff stats
path: root/trunk/hapaxlink.sh
blob: 286c43d408833b92351608ecfe30cf2d44f80c8f (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
#!/bin/bash

file="$1";
headFile="$2";
shift 2;
glob="$@";                       # *.hapax

tempFile="${RANDOM}.tmp"

echo -n "Linking \"$file\""
# Begin
cat "$headFile" > "$tempFile";
echo -n "."
# Link words to files they appear in
for word in `sort "$file"`; do
    f=`grep -liwq "^$word$" $glob`;
    link="`basename $f .hapax`.html"
    echo "[$word]($link)" >> "$tempFile";
    echo -n "."
done

# Make the changes happen
rm "$file"
mv "$tempFile" "$file"

echo "Done."