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!
while read line; do
if grep "<p>~" tpl >/dev/null 2>&1; then
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 $line >> tpf
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