screwloose
MIS
Okay, I was bored so I wrote a script that removes double quotes from around words in a text document.
Not hard but I was bored.
#!/usr/dt/bin/dtksh
# removes double quotes around words from a text document.
file=$1
char='"'
rm /tmp/newtext 2>/dev/null
oldword=
while read line
do
set -A word $(echo $line)
numwords=${#word[@]}
i=0
while (( i < numwords )); do
w=${word}; wordlen=${#word}
if [[ $wordlen -eq 1 ]]; then
wordshort=0
else
((wordshort=wordlen-1))
fi
f=${w:0:1}; l=${w:$wordshort}
if [[ $f = $char && $l = $char ]]; then
b=0
e=2
((ws=wordlen-1))
while (( b < ws )); do
if [[ $b -eq 0 ]]; then
d=2
typeset -L$d ch=$w
if [[ $i -eq 0 ]]; then
print -n "" >> /tmp/newtext
else
print -n " " >> /tmp/newtext
fi
else
typeset -L$e ch=$w
typeset -R1 chw=$ch
print -n $chw >> /tmp/newtext
fi
((e+=1))
((b+=1))
done
else
newword=$w
if [[ $newword != $oldword ]]; then
if [[ $i -eq 0 ]]; then
print -n "" >> /tmp/newtext
else
print -n " " >> /tmp/newtext
fi
fi
print -n $w >> /tmp/newtext
oldword=$w
fi
((i+=1))
done
print >> /tmp/newtext
done < $file
Not hard but I was bored.
#!/usr/dt/bin/dtksh
# removes double quotes around words from a text document.
file=$1
char='"'
rm /tmp/newtext 2>/dev/null
oldword=
while read line
do
set -A word $(echo $line)
numwords=${#word[@]}
i=0
while (( i < numwords )); do
w=${word}; wordlen=${#word}
if [[ $wordlen -eq 1 ]]; then
wordshort=0
else
((wordshort=wordlen-1))
fi
f=${w:0:1}; l=${w:$wordshort}
if [[ $f = $char && $l = $char ]]; then
b=0
e=2
((ws=wordlen-1))
while (( b < ws )); do
if [[ $b -eq 0 ]]; then
d=2
typeset -L$d ch=$w
if [[ $i -eq 0 ]]; then
print -n "" >> /tmp/newtext
else
print -n " " >> /tmp/newtext
fi
else
typeset -L$e ch=$w
typeset -R1 chw=$ch
print -n $chw >> /tmp/newtext
fi
((e+=1))
((b+=1))
done
else
newword=$w
if [[ $newword != $oldword ]]; then
if [[ $i -eq 0 ]]; then
print -n "" >> /tmp/newtext
else
print -n " " >> /tmp/newtext
fi
fi
print -n $w >> /tmp/newtext
oldword=$w
fi
((i+=1))
done
print >> /tmp/newtext
done < $file