#!/bin/bash
# you can blame this mess on Terry Vessels, aka "grouch"
# released under the terms of the GPL, http://www.gnu.org/licenses/gpl.txt
# an attempt to create a script to generate some bibliography-style
# link lists from groklaw.net articles
s_file=$1
d_file=$2
if [ ! -f ${s_file} ]||[ -z ${s_file} ]||[ -z ${d_file} ]
then
echo "Usage: $0 [source file] [destination file]"
exit
fi
if [ -e $2 ]
then
echo "destination file $2 exists!"
echo "either choose another filename to write to, or rm $2"
exit
fi
# get everything between
# and
# change all CR to LF, then all LF to SPACE
# put back LF in front of each
art_start=$(grep -n '' ${s_file} |\
awk '{line_num=substr($1,0,index($1,":")-1); print line_num}')
art_end=$(grep -n '' ${s_file} |\
awk '{line_num=substr($1,0,index($1,":")-1); print line_num}')
art_len=$((1 + ${art_end} - ${art_start}))
head -${art_end} ${s_file} | tail -${art_len} |\
tr '\015' '\012' | tr '\012' '\040' |\
sed -e 's//<\/a>\
/g' |\
grep "")-1)
start_a=index($2,"")
start_l=index($2,"\">")+2
link_text=substr($2, start_l, start_a - start_l)
print count " " $0 " " url "
"
}' > ${d_file}