[OS X TeX] search & replace commands
Steffen Lund Hokland
hokland at mr.au.dk
Fri Jul 9 09:16:40 CEST 2004
Hi,
There is the alternative of writing a BASH-script (or in some
alternative shell-language I guess) using the sed-command. I did this
when I had to replace occurences of 'A##', 'B###' and 'C###' with
'\hyperref{A##}{A##}', '\hyperref{B###}{B###}' and
'\hyperref{C###}{C###}', respectively, where ##, ### where 2 and 3
digit integers (with leading zeroes for integeres below 10 and 100).
I've attached the script (which is basically a very slow and dirty
solution - no nice exits and stuff like that I'm affraid) bellow in
case you are interested (if needed, I can give you some assistance with
the modifications - although I'm nowhere near an expert).
Good luck
Steffen
######################Appended script:#########################
#!/bin/bash
# This script recursively replaces '$ABSTRACTNO' with
'\hyperref{$ABSTRACTNO}{$ABSTRACTNO}'#
ARGS=1
BADARGS=1
NOFILE=2
TMP=.tmp
HYPER=hyperlinked
SEDFILE=sedcommands.sed
if [ $# -ne $ARGS ]
then
echo "Usage: `basename $0` filename"
exit $BADARGS
fi
if [ ! -f "$1" ]
then
echo "Usage `basename $0` filename"
exit $NOFILE
else
FILENAME=$1
fi
I=1
while [ $I -le 116 ]
do
if [ $I -le 24 ]
then
ABSTRACT=0$I
POS=${#ABSTRACT}
let "POS-=2"
ABSTRACT=A${ABSTRACT:$POS:2}
LINKOFABSTRACT=backslashhyperlink\{${ABSTRACT}\}\{${ABSTRACT}\}
COMMAND=s/${ABSTRACT}/${LINKOFABSTRACT}/g
echo ${COMMAND} >> ${SEDFILE}
fi
if [ $I -le 116 ]
then
ABSTRACT=00$I
POS=${#ABSTRACT}
let "POS-=3"
ABSTRACT="B${ABSTRACT:$POS:3}"
LINKOFABSTRACT=backslashhyperlink\{${ABSTRACT}\}\{${ABSTRACT}\}
COMMAND=s/${ABSTRACT}/${LINKOFABSTRACT}/g
echo ${COMMAND} >> ${SEDFILE}
fi
if [ $I -le 72 ]
then
ABSTRACT=00$I
POS=${#ABSTRACT}
let "POS-=3"
ABSTRACT="C${ABSTRACT:$POS:3}"
LINKOFABSTRACT=backslashhyperlink\{${ABSTRACT}\}\{${ABSTRACT}\}
COMMAND=s/${ABSTRACT}/${LINKOFABSTRACT}/g
echo ${COMMAND} >> ${SEDFILE}
fi
let "I+=1"
done
sed -f ${SEDFILE} $FILENAME > ${FILENAME}${TMP}
sed 's/backslash/\\/g' ${FILENAME}${TMP} > ${FILENAME}${TMP}${TMP}
mv ${FILENAME}${TMP}${TMP} ${HYPER}${FILENAME}
rm -f ${FILENAME}${TMP}
rm -f ${SEDFILE}
echo 'done!'
############################################################
Confucius say: Man who play in root, eventually kill tree.
___________________________________________
Steffen Lund Hokland, MSc.
Research Assistant
The MR-Research Centre
Clinical Inst.
Aarhus University Hospital
Skejby Hospital
DK-8200 Aarhus
Denmark
Phone Office : +45 89495264
Phone Home : +45 86166608
Phone Mobile : +45 61307461
e-mail : hokland at mr.au.dk
___________________________________________
-----------------------------------------------------
Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
Please see <http://www.esm.psu.edu/mac-tex/> for list
guidelines, information, and LaTeX/TeX resources.
More information about the macostex-archives
mailing list