#!/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 anchor tags # in selected files (transcripts, etc) from groklaw # # s_file == source file # d_file == destination, without anchors # l_file == destination, with anchor links s_file=$1 d_file=$2 l_file=$3 #if [ ! -f ${s_file} ]||[ -z ${s_file} ]||[ -z ${d_file} ] #then # echo "Usage: $0 [source file] [destination file] [link 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 #if [ -e $3 ] #then # echo "link file $3 exists!" # echo "either choose another filename to write to, or rm $2" # exit #fi # get everything between # and # change all CR (\015) to LF (\012) # put back LF in front of each < and after each > # take out blank lines # awk to insert an [[number]] tag # for each

' ${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' |\ sed -e 's//>\ /g' |\ grep '[^[:space:]].' | tee $d_file |\ awk '{FS=""}{ if ($1=="<" && (($2=="p" && $3!="r") || ($2=="b" && $3=="r"))) { print $0 "[["NR"]]
" } else { print $0 } }' > $l_file