Q: Is there any way to use grep and sed with a string variable rather than with a file?
The problem: Im running through a LARGE (about 10,000 lines) xhtml file and need to replace every instance of lines beginning <p>~
The following code works but takes a long time mainlly because an in/out operation needs to be carried out on each line. If I could read from a string rather than a file it would take a much shorter time!
Code:
#!/bin/bash
count=$((0))
>tpf
echo "waiting....."
while read line; do
echo $line>tpl
echo $line>tpl
if grep "<p>~" tpl >/dev/null 2>&1; then
count=$((count+1))
sed s/"<p>"/""/ tpl >tpl2;cp tpl2 tpl
echo "<p style='font-size:1.4em; text-align: center; margin-top: 2em;' id='ch$count'>"$line >> tpf
#echo $count$line
else
echo $line >> tpf
fi
done<testbook
rm tpl
echo "done!! $count lines were changed"
I'm new to bash, and am trying to convert php and c programs to bash.
Any suggestions would be appreciated
Thanks,
Frank